datatable.js显示所有行

时间:2013-09-13 08:35:08

标签: asp.net-mvc jquery datatable

我有数据表显示所有行而不是默认的10

为什么?

>    <script type="text/javascript" charset="utf-8">
>     $(document).ready(function () {
>         $('#TableList').dataTable({
>             "sEcho": 3,
>             "iDisplayLength": 10,
>             "bJQueryUI": true,
>             "sPaginationType": "full_numbers",
>             "bProcessing": true,
>             "bServerSide": true,
>             "sAjaxSource": '@Url.Action("DataList", "Home")',
>             "sAjaxDataProp": "aaData",
>             "aoColumns": [   { "mData": "AccountName", sDefaultContent: "", "bSortable": true },   { "sType": "Launched",
> sDefaultContent: "", "bSortable": true, "iDataSort": 4 },
>             { "mData": "InterestFreq", sDefaultContent: "", "bSortable": true },
>     { "mData": "Penalty", sDefaultContent: "", "bSortable": true }
>             ]
>         });
>     }); </script> <div class="demo_jui">
>     <table id="TableList" class="display">
>         <thead>
>             <tr>
>                 <th>Account Name</th>
>                 <th>Launched</th>
>                 <th>Interest Frequency</th>
>                 <th>Penalty</th>
>                 <th></th>
>             </tr>
>         </thead>
>         <tbody>
>         </tbody>
>     </table> </div>

- MVC

public ActionResult DataList(){
    DCMEntities oData = new DCMEntities();
    var oList = (from w in oData.DCMAccountsDatabases orderby w.AccountName select new { w.AccountName, Launched = w.Launched , w.InterestFreq, w.Penalty }).Take(1000);
    return Json(new { iTotalRecords = oList.Count(), iTotalDisplayRecords = oList.Count(), aaData = oList }, JsonRequestBehavior.AllowGet);
}

我希望数据表每页显示10行,即使我添加了“iDisplayLength”:10,id似乎无法正常工作

1 个答案:

答案 0 :(得分:0)

aaData应该只有10长。

所以它应该是:

return Json(new { iTotalRecords = oList.Count(), iTotalDisplayRecords = oList.Count(), 
   aaData = oList.Take(10) }, JsonRequestBehavior.AllowGet);