我在我的视图中使用了jQuery Datatable,如下所示;
<table id="CategoryGrid">
<thead>
<tr>
<th>Id</th>
<th>
Name
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Datatable的javascript代码;
var catGrid = $('#CategoryGrid').dataTable({
"bPaginate": true,
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": "@Url.Action("CategoriesGet")",
"aoColumns": [
{
"sName": "CategoryId",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Company/Details/' + oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "CategoryName" },
{ "sName": "CategoryDescription" }
]
});
返回的JSON数据如下;
{"sEcho":"1","iTotalRecords":10,"TotalDisplayRecords":10,"aaData":[["1","For Sale","asdfasdf"],["2","Jobs","asdfasdfasdf"],["3","Classes","asdfasdf"],["4","Vehicles","asdfasdsadfa"],["45","test","asdff"],["46","asfd","sdf"],["47","test","sdf"],["48","another test","sfsdfsdf"],["49","another test","sdfsdfsdf"],["50","asfd","asdf"]]}
为什么我要显示NaN条目的NaN
答案 0 :(得分:4)
看起来您在iTotalDisplayRecords
字词中输入了拼写错误,您忘记了 i 字母前缀...
另外,请看一下这个Server-side processing
一般来说,服务器的回复应包含:iTotalRecords
,iTotalDisplayRecords
,sEcho
和aaData
属性......
sEcho:从客户端发送的未经更改的sEcho副本。此参数将随每次绘制而变化(它基本上是绘制计数) - 因此实现此参数非常重要。请注意,出于安全原因,强烈建议您将此参数强制转换为整数,以防止跨站点脚本(XSS)攻击。