单击时是否未获取数据表编辑ID?

时间:2014-04-03 12:36:01

标签: jquery asp.net-mvc-4

我一直处于奇怪的境地。

我的下面的代码非常完美:但我需要与之不同的是:

       @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但删除,更新,不工作? ??有趣的是Add正在运作..

我认为ID错位,所以行编辑&amp;删除没有完成

非常感谢

此致

1 个答案:

答案 0 :(得分: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>

感谢各位朋友的时间 此致