0

我有显示所有行而不是默认的 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 似乎也不起作用

4

1 回答 1

0

aaData 应该只有 10 长。

所以应该是:

return Json(new { iTotalRecords = oList.Count(), iTotalDisplayRecords = oList.Count(), 
   aaData = oList.Take(10) }, JsonRequestBehavior.AllowGet);
于 2013-09-13T13:35:07.480 回答