如何在数据表中进行服务器端分页?

时间:2015-12-04 14:05:27

标签: javascript ajax data-paging

我正在使用MVC。我有大量的数据,我需要只有分页限制的数据。例如,如果页面大小为10,我想在我的数据库中只获得前10条记录。

这是我的HTML:

<table class="table table-striped table-bordered table-hover" id="data_table">
  <thead>
    <tr>
    <th> Anket Id  </th>
    <th> Anket Adı </th>
    <th> Katılımcı </th>
    <th> Soru      </th>
    <th> Aktif Gün </th>
    <th> Dil       </th>
    <th> Durum     </th>
    <th> Kayıt Tarihi </th>            
</table>

这是我的JS:

 var table =  $('#data_table').DataTable({

            "processing": true,
            "serverSide": true,
            "ajaxSource": "/Survey/ActiveSurveysPaging",
            "dataSrc": "",
            "aoColumns": [
                { "mDataProp": "Anket Id" },
                { "mDataProp": "Anket Adı" },
                { "mDataProp": "Katılımcı" },
                { "mDataProp": "Soru" },
                { "mDataProp": "Aktif Gün" },
                { "mDataProp": "Dil" },
                { "mDataProp": "Durum" },
                { "mDataProp": "Kayıt Tarihi"}
            ],
       ..........

这就是我的服务器返回的json:

 {"sEcho": 3,"iTotalRecords" : 1013,"iTotalDisplayRecords" : 1013,"aaData" :   [["56523938aa9c580dac1858e5","anket-0","1001","8","11","TR","Aktif","22.11.2015 23:52"],

["5652393aaa9c580dac185918","anket-1","1000","8","11","TR","Aktif","22.11.2015 23:52"]]}

当我运行程序时,它在加载数据表时给出了“无法读取未定义的属性长度”错误。在哪里我做错了,谢谢你的任何解决方案。

1 个答案:

答案 0 :(得分:0)

尝试JqGrid之类的内容 如果你想用分页实现你自己的表,那就像Jqgrid

一样