问题
I have a problem, which was originally set out in this question. I thought it was working, but not so.
I'm using datatables v1.10.19 with jQuery 3.3.1 and Bootstrap 3.3.7
Now, my problem is that regardless of how many pages of data I have, the pager is showing one paging button (as if all the data fits on 1 page, when it doesn't).
My config object looks like this:
{
"processing": true,
"serverSide": true,
"ajax": {
url: url,
type: ajax.requestPOST
},
"order": [[1, "asc"]],
"lengthMenu": [[-1, 500, 1000, 2500, 5000], ["All", 500, 1000, 2500, 5000]],
"columns": eventsSvr.grid.columns,
"columnDefs": eventsSvr.grid.columnDefs,
"language": $.extend({}, appDt.loadingSpinner, appDt.lengthMenuText),
dom: 'ltp'
}
My return payload looks like this:
{
"draw": 4,
"recordsTotal": 3727,
"recordsFiltered": 500,
"data": [ big data array here ]
}
As can be seen the data has 3700+ rows.
The page size is 500.
Yet, the grid only has 1 page. It has 500 rows and there are no buttons on the pager to move to any subsequent pages.
So, the user can only view the first 500 records.
Any ideas as to what is going on with the pager?
回答1:
DataTables calculates number of pages based on recordsFiltered
and your page size. It contains total number of records after filtering has been applied.
When search is performed, recordsFiltered
may not be equal to recordsTotal
.
Your server-side handler should calculate total number of records without applying the search criteria and return it in recordsTotal
and then calculate total number of records after applying the search criteria and return it in recordsFiltered
.
This allows DataTables to display in the information section the following message:
Showing 1 to 10 of
recordsFiltered
entries (filtered fromrecordsTotal
total entries)
You can read more about proper format of the returned data in server-side processing mode in the official documentation.
来源:https://stackoverflow.com/questions/60716362/datatables-pager-showing-one-page-when-there-are-many