[英]Datatables on server side processing with jQuery
I am new to datatables.我是数据表的新手。 I am trying to find solution for server side processing since last two days but didnt find the solution.自前两天以来,我一直在尝试寻找服务器端处理的解决方案,但没有找到解决方案。
My JS code is我的JS代码是
this.$("#example").DataTable({
"processing": true,
"serverSide": true,
"ajax": "../employees.json",
"columns": [{
"data": "Name"
}, {
"data": "Age"
}, {
"data": "Country"
}, {
"data": "Address"
}, {
"data": "Married"
}]
});
Datatable renders JSON in table format. Datatable 以表格格式呈现 JSON。 But sorting, pagination and search operation is not working.但是排序、分页和搜索操作不起作用。 It shows all results on the first page no matter how much value I have selected from dropdown无论我从下拉列表中选择了多少值,它都会在第一页上显示所有结果
Also at bottom it shows message like "Showing 0 to 0 of 0 entries (filtered from NaN total entries)"同样在底部它会显示类似“显示 0 到 0 个条目中的 0 个条目(从 NaN 总条目过滤)”的消息
If I pass serverSide: false.如果我通过 serverSide: false。 everything works fine.一切正常。 But I want server side processing of the same但我想要相同的服务器端处理
Any help would be appreciated任何帮助,将不胜感激
When you set serverSide to true, you are telling DataTables that the server will handle all the sorting and paging instead of DataTables.当您将 serverSide 设置为 true 时,您是在告诉 DataTables 服务器将处理所有排序和分页而不是 DataTables。 DataTables will just display the data as-is from the server. DataTables 只会按原样显示来自服务器的数据。
So if your server is ignoring all the sorting and paging parameters sent from DataTables, then the data will look funny.因此,如果您的服务器忽略从 DataTables 发送的所有排序和分页参数,那么数据看起来会很有趣。 (In your case it seems that the server is listing all records, regardless of the requested page size). (在您的情况下,无论请求的页面大小如何,服务器似乎都列出了所有记录)。
You have two options:您有两个选择:
In the return of your json form must have these:在你的 json 表单的返回中必须有这些:
iTotalRecords : (Total rows),
iTotalDisplayRecords : (Total rows to display in your grud),
aaData : {(Your data)}.
Works for me.为我工作。
Ther are some options that you must set true有一些选项必须设为 true
eg例如
this.$("#example").DataTable({
"processing": true,
"serverSide": true,
"ajax": "../employees.json",
"columns": [{
"data": "Name"
}, {
"data": "Age"
}, {
"data": "Country"
}, {
"data": "Address"
}, {
"data": "Married"
}],
'scrollCollapse': true,
'ordering': true,
'order': [[0, 'asc']],
'searching': true,
'paging': true,
});
This may be late but you can use fnInfoCallback so for example:这可能会晚,但您可以使用 fnInfoCallback 例如:
"fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
if (isNaN(iTotal)) {
return '';
}
return "Showing " + iStart +" to "+ iEnd + " of " + iTotal + " entries";
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.