【问题标题】:jQuery datatable reDraw issuejQuery数据表重绘问题
【发布时间】:2011-07-20 08:52:06
【问题描述】:

我是 jQuery 和 ASP.Net MVC 的新手。我正在开发一个使用 jQuery 的 mvc 应用程序。

我在 jQuery 数据表中遇到问题。在更新或删除方法之后,我们需要再次重新构建数据表。我使用 jquery 完成了它,但我无法像以前那样加载数据表。请帮我解决这个问题。

  <table id="ViewxxTable" width="100%">    //Here is the table I want to reconstruct 
     <thead>
       <tr>
            <th>SN No</th>
            <th>Item code</th>
      </tr>
    </thead>
    <tbody>
<%     
    List<InSys.Models.xxDetailClass> xxdetailLst =     (List<InSys.Models.xxDetailClass>)Session["xxddetailLst"];
    foreach (InSys.Models.xxDetailClass grnd in xxdetailLst)
        {
%>
   <tr>
      <td><%= grnd.SnNo%></td>
      <td><%= grnd.ItemCode%></td>
      <td>
  </tr>

<%
       }
%>
  </tbody>
</table>

jquery

    oTable = $('#ViewxxTable').dataTable({
                 "bPaginate": false,
                 "bJQueryUI": true,
                 "bRetrieve": true,
                 "bDestroy": true,
                "sPaginationType": "full_numbers"
}); 

【问题讨论】:

    标签: jquery datatables


    【解决方案1】:
    $(document).ready(function () {
        oTable = $("#tableId").dataTable({ 
            "bPaginate": true,
            "bJQueryUI": true,
            "bRetrieve": true,
            "sPaginationType": "full_numbers"
    });
    
    $("#tableId").dataTable().fnDestroy();    // destroy the old datatable
    oTable = $("#tableId").dataTable({
        "bPaginate": true,
        "bJQueryUI": true,
        "bRetrieve": true,
        "sPaginationType": "full_numbers"
    

    【讨论】:

      【解决方案2】:

      将你的数据表初始化代码放在一个函数中,然后在重建你的表后调用该函数......就像这样-

      function IntializeDatatable(tableId){
      $('#'+tableId).dataTable();
      }
      

      内部删除。更新方法调用它-

      IntializeDatatable('ViewxxTable');
      

      【讨论】:

      • 感谢 Vivek 的回答......但它没有工作,当我在插入或更新后重新构建数据表时,它显示只有表头和表尾在数据表中数据显示在带有该标题和后缀的普通 html 表...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多