jquery datatable分页不显示页数

嗨我正在使用jquery数据表1.9.4用于人口服务器端处理表。数据正确加载。 但是分页没有按预期工作。 实际上它有超过30行,下一个,前一个和页码不起作用 在此处输入图像描述

var sTableAllCustomers = $('#tblAllCustomers').dataTable({ "bDestroy": true, "bProcessing": true, "bServerSide" : true, "bLenthChange" : false, "iDisplayLength": 5, "aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]], "sPaginationType" : "full_numbers", "sAjaxSource" : "loadAllCustomers", "oLanguage" : { "sSearch" : "Search By Email ID:" }, "aoColumns" : [ {"sTitle" : "No.","mData" : null,"aTargets": [ 0 ], "fnRender" : function(obj) { var columnIndex = obj.oSettings._iDisplayStart + obj.iDataRow+1 return columnIndex; } }, {"sTitle" : "Email ID","mData" : "email", "bSearchable" : true}, {"sTitle" : "Devices","mData" : "device", "bSearchable" : false}, {"sTitle" : "App Edition","mData" : "edition", "bSearchable" : false}, {"sTitle" : "Account Type","mData" : "accountType", "bSearchable" : false}, {"sTitle" : "Activated Date","mData" : "activatedDate", "bSearchable" : false}, {"mData" : "id", "bSearchable": false, "mRender": function (data, type, full ) { return ' '; } } ], "fnServerData" : function(sSource, aoData, fnCallback) { $.ajax({ "dataType" : 'json', "type" : "GET", "url" : sSource, "data" : aoData, "success" : fnCallback }); }, }); 

服务器端代码

 int totalListSize = modals != null ? modals.size() : 0; CustomerDataTableObject dataTableObject = new CustomerDataTableObject(); // the total data in db for datatables to calculate page no. and // position dataTableObject.setiTotalDisplayRecords(totalListSize); // the total data in db for datatables to calculate page no. dataTableObject.setiTotalRecords(totalListSize); dataTableObject.setsEcho(Integer.parseInt(request.getParameter("sEcho"))); dataTableObject.setAaData(modals); Gson gson = new Gson(); String json = gson.toJson(dataTableObject); 

您正在使用存储在totalListSize变量中的相同值初始化两个参数iTotalRecordsiTotalDisplayRecords 。 但是,变量totalListSize保存返回的记录数,但它应该保存数据库中的记录总数。

从文档 :

iTotalRecords

过滤前的总记录(即数据库中的记录总数)

iTotalDisplayRecords

过滤后的总记录(即应用过滤后的记录总数 – 不仅仅是此结果集中返回的记录数)

您需要单独计算数据库中的记录总数,并将其分配给iTotalRecordsiTotalDisplayRecords

例如,如果您有30条记录,并且只能在一个页面上显示5条记录,那么您的响应应该是这样的:

 { "sEcho": 1, "iTotalRecords": 30, "iTotalDisplayRecords": 30, "aaData": [ { "DT_RowId": "row_8", "DT_RowClass": "gradeA", "0": "Gecko", "1": "Firefox 1.5", "2": "Win 98+ / OSX.2+", "3": "1.8", "4": "A" }, // ... 4 more entries ... ] }