2014-04-03 45 views
0

我一直處於奇怪的境地。數據表編輯ID在點擊時沒有獲取?

下面我的代碼工作完美:但是我需要是不同的:

 @section head{ 

<script type="text/javascript"> 

       $(document).ready(function() { 
        debugger; 
        $('#myDataTable').dataTable({ 
         "bJQueryUI": true, 
         "bProcessing": true, 
         "bServerSide": true, 
         "bJQueryUI": true, 
         "sAjaxSource": "Home/AjaxHandler", 

         "sDeleteURL": "/Home/DeleteData", 
         "sUpdateURL": "/Home/UpdateData", 
         "sAddURL": "/Home/AddData", 

         "aoColumns": [ 
               { 
                "sName": "Lead_Id" 

               }, 

            { "sName": "Contact_Name" }, 
            { "sName": "Contact_Address" }, 
            { "sName": "Lead_Source" }, 
            { "sName": "Domain" }, 
         ] 
        }).makeEditable({ 
         sUpdateURL: "/Home/UpdateData", 
         sAddURL: "/Home/AddData", 
         sDeleteURL: "/Home/DeleteData", 

         sAddNewRowFormId: "formAddNewLead", 
         sAddNewRowButtonId: "btnAddNewLead", 
         sAddNewRowOkButtonId: "btnAddNewLeadOk", 
         sAddNewRowCancelButtonId: "btnAddNewLeadCancel", 
         sDeleteRowButtonId: "btnDeleteLead", 

         fnShowError: function (message, action) { 
          switch (action) { 
           case "update": 
            jAlert(message, "Update failed"); 
            break; 
           case "delete": 
            jAlert(message, "Delete failed"); 
            break; 
           case "add": 
            $("#lblAddError").html(message); 
            $("#lblAddError").show(); 
            break; 
          } 
         }, 
         fnStartProcessingMode: function() { 
          $("#processing_message").dialog(); 
         }, 
         fnEndProcessingMode: function() { 
          $("#processing_message").dialog("close"); 
         } 
        }); 
       }); 

      </script> 
    } 


    <div id="demo"> 
    <h2>Customization</h2> 

    <table id="myDataTable" class="display"> 
         <thead> 
         <tr> 
          <th>View-Details</th> 
          <th>Contact Person</th> 
          <th>Contact Address</th> 
          <th>Lead Source</th> 
          <th>Domain</th> 
         </tr> 
    </thead> 
    <tbody> 
         @foreach (var item in Model.Lead_complete_list) 
         { 
         <tr id="@item.Lead_Id"> 

           <td>@item.Contact_Name</td> 
           <td>@item.Contact_Address</td> 
           <td>@item.Lead_Source</td> 
           <td>@item.Domain</td> 

          </tr> 
         } 
    </tbody> 
        </table> 

我努力的修改是很簡單的,即我不想顯示ID,而不是我想依觀衆顯示點擊鏈接,我需要獲得該行的ID?

我試過這樣,當我這樣做,編輯和刪除功能不黯然工作: 在aoColumns我一直喜歡

"aoColumns": [ 

         { 
          "sName": "Lead_Id", 
          "bSearchable": false, 
          "bSortable": false, 
          "fnRender": function (oObj) 
          { 
           return '<a href=\"LeadSortModel' + oObj.aData[0] + '\">CRUD !t</a>'; //Is this correct ?? 
          } 
         },   
         { "sName": "Contact_Name" }, 
         { "sName": "Contact_Address" }, 
         { "sName": "Lead_Source" }, 
         { "sName": "Domain" } 
        ] 

的鏈接讓我的ID,以控制器的操作方法是必需的,但刪除,更新,不工作? ??有趣的是添加工作..

我想ID是放錯了地方因此行編輯&刪除是沒有得到做

任何辦法解決,非常感謝

問候

+0

我認爲你必須用''標籤和關閉嵌套問題'}' – Oybek

+0

不,你不需要,腳本標籤後面的'}'有點混亂。 – Oybek

+0

沒有隊友我忘了給@部分。現在編輯..問題是在我堅信aColumns ..任何解決方法是有益的隊友。 –

回答

0

嗯終於有輕微做到了變化 。

此代碼工作正常,以我的確切需求:

@section head{ 
<script type="text/javascript"> 

      $(document).ready(function() { 
       debugger; 
       $('#myDataTable').dataTable({ 
        "bJQueryUI": true, 
        "sPaginationType": "full_numbers", 
        "bProcessing": true, 
        //"bServerSide": true, //we should avoid this 
        "aoColumns": [ 

         { 
          "sName": "Lead_Id", 
          "bSearchable": false, 
          "bSortable": false, 
          "fnRender": function (oObj) { 

           return '<a href=\"Home\\LeadWizard\\' + oObj.aData[0] + '\">To Wizard</a>'; 
          } 
         }, 
         { "sName": "Contact_Name" }, 
         { "sName": "Contact_Address" }, 
         { "sName": "Lead_Source" }, 
         { "sName": "Domain" } 
        ] 
       }).makeEditable({ 
        sUpdateURL: "/Home/UpdateData", 
        sAddURL: "/Home/AddData", 
        sDeleteURL: "/Home/DeleteData", 

        sAddNewRowFormId: "formAddNewLead", 
        sAddNewRowButtonId: "btnAddNewLead", 
        sAddNewRowOkButtonId: "btnAddNewLeadOk", 
        sAddNewRowCancelButtonId: "btnAddNewLeadCancel", 
        sDeleteRowButtonId: "btnDeleteLead", 

        fnShowError: function (message, action) { 
         switch (action) { 
          case "update": 
           jAlert(message, "Update failed"); 
           break; 
          case "delete": 
           jAlert(message, "Delete failed"); 
           break; 
          case "add": 
           $("#lblAddError").html(message); 
           $("#lblAddError").show(); 
           break; 
         } 
        }, 
        fnStartProcessingMode: function() { 
         $("#processing_message").dialog(); 
        }, 
        fnEndProcessingMode: function() { 
         $("#processing_message").dialog("close"); 
        } 
       }); 
      }); 

     </script> 
} 


<div id="demo"> 
<h2>Customization</h2> 

<table id="myDataTable" class="display"> 
        <thead> 
        <tr> 
         <th>Details</th> 
         <th>Contact Person</th> 
         <th>Contact Address</th> 
         <th>Lead Source</th> 
         <th>Domain</th> 
        </tr> 
</thead> 
<tbody> 
        @foreach (var item in Model.Lead_complete_list) 
        { 
        <tr id="@item.Lead_Id"> 
         <td>@item.Lead_Id</td> **// need to add this but need to hide from display** 
          <td>@item.Contact_Name</td> 
          <td>@item.Contact_Address</td> 
          <td>@item.Lead_Source</td> 
          <td>@item.Domain</td> 

         </tr> 
        } 
</tbody> 
       </table> 

感謝您的朋友爲您的時間 問候