DataTables分页器在有很多页面时显示一页 [英] DataTables Pager Showing One Page when there Are Many
问题描述
我有一个问题,最初是在此问题中提出的。我以为它可以正常工作,但不是这样。
我正在使用带有jQuery 3.3.1和Bootstrap 3.3.7的数据表v1.10.19
现在,我的问题是,无论我拥有多少页数据,该寻呼机都会显示一个寻呼按钮(好像所有数据都放在一页上,而实际上却不在一页上)。 / p>
我的配置对象如下:
{
processing:true,
serverSide:true,
ajax:{
url:url,
type:ajax.requestPOST
},
order:[[1, asc]],
lengthMenu:[[-1,500,1000,2500,5000],[全部,500,1000,2500,5000 ]],
columns:eventsSvr.grid.columns,
columnDefs:eventsSvr.grid.columnDefs,
language:$ .extend({},appDt.loadingSpinner, appDt.lengthMenuText),
dom:'ltp'
}
我的返回有效载荷如下:
{
draw:4,
recordsTotal :3727,
recordsFiltered:500,
data:[此处的大数据数组]
}
可以看到数据有3700多行。
页面大小为500。
但是,网格只有1页。它有500行,并且在寻呼机上没有按钮可以移至任何后续页面。
因此,用户只能查看前500条记录。
关于寻呼机发生什么的任何想法?
DataTables根据 recordsFiltered
和您的页面大小来计算页面数。它包含应用过滤后的记录总数。
执行搜索时, recordsFiltered
可能不相等到 recordsTotal
。
您的服务器端处理程序应在不应用搜索条件的情况下计算记录总数并返回在 recordsTotal
中,然后在应用搜索条件后计算记录总数,并在 recordsFiltered
中将其返回。
这允许DataTables在信息部分显示以下消息:
显示1到10的
recordsFiltered
个条目(从recordsTotal
个条目中过滤)
您可以在官方文档。
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?
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.
这篇关于DataTables分页器在有很多页面时显示一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!