javascript - 如何启用 Datatables 分页按钮以获得无限结果?
问题描述
如何配置Datatable以使分页按钮始终处于启用状态,并触发ajax
数据加载方法?
我的数据太大而无法一次加载,因此我使用“ajax”选项的“function”值来调用自定义 JSON 加载方法,该方法可以重复调用以加载下一页结果。
我希望用户单击“上一个”和“下一个”按钮来触发该功能。但是,默认情况下,Datatables 似乎假定“ajax”方法第一次加载所有数据,因此如果结果适合当前表而不需要分页,则分页按钮被禁用。
我尝试使用浏览器的检查器通过 CSS 属性动态启用它们,但看起来这只是一种美化效果,它们实际上并没有触发 ajax 回调。
我该如何解决?这甚至是数据表支持的东西吗?
解决方案
You should put serverSide
option to true
to use ajax.
If you want to make pagination and you don't know how many records you have, you should return this in the ajax response { ... "recordsTotal": Length of table, "recordsFiltered": int.MaxValue, ...}
and use info: false
& pagingType: 'simple'
options to hide the number of records and show just Next and Previous buttons without pages.
dataTable({
......
processing: true,
serverSide: true,
pagingType: 'simple',
info: false,
lengthMenu: [10, 25, 50, 100, 250, 500, 1000],
searchDelay: 1000,
pageLength: 10,
ajax: {
url: 'url',
type: 'get'
}
推荐阅读
- javascript - 嵌入消息的记录字段
- javascript - 使用数组访问(深度)嵌套对象属性
- postgresql - PostgresSQL 无法读取我桌面上的 csv 文件
- xamarin - 自定义渲染器在 iOS 上的行为不符合预期
- c# - 如何从另一个 Ienumerable 获取 SelectList
- javascript - 当我的输入为空时,为什么 $(...).val() == "" false?
- testing - 需要一个用于 codeceptjs 的自动完成插件
- javascript - Vue.js 对话框/模态在父组件上关闭
- python - 如何解决此错误:“RefVariable”对象不支持项目分配?
- c# - 如何正确保护忘记密码的端点