jquery - 无法在数据表上实现分页
问题描述
这是我的代码片段(其余的只是列定义和 initComplete 实现):
table = jq('#example').DataTable( {
"select":{
"style": "multi"
},
"processing": true,
"serverSide": true,
"lengthChange":true,
"pageLength":10,
"order":[[1,"asc"]],
"dom": "Bfrtip",
"ajax": '/'+localeCodeShort+'/umbrella/api/get-users',
});
它显示了抽签中的所有记录(总共 103 条),而不是只有 10 条。不知道为什么?
更新
这是我的 HTML:
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Status</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
这是我的 JSON 示例:
{
"draw": 1,
"recordsTotal": 103,
"recordsFiltered": 103,
"data": [
[
"",
"1",
"Jonathan",
"Reid",
"reid@gmail.com",
"1",
""
],
[
"",
"2",
"Someone",
"Foryou",
"someadd@gmail.com",
"1",
""
]
]
}
这是我的列定义:
\"columnDefs\": [
{
\"orderable\":false,
\"className\":\"select-checkbox\",
\"targets\":0,
\"width\":\"5%\"
},
{
\"targets\": " . $dataTable -> actionCol . ",
\"data\": null,
\"defaultContent\": \"" . $btnHtml . "\"
},
{
\"targets\":-2,
\"className\":\"select-status\",
\"searchable\":true
},
],
另外,我目前返回所有 103 条记录
解决方案
您是否尝试将“分页”变量设置为 true?
table = jq('#example').DataTable( {
"select":{
"style": "multi"
},
"processing": true,
"serverSide": true,
"lengthChange":true,
"paging":true,
"pageLength":10,
"order":[[1,"asc"]],
"dom": "Bfrtip",
"ajax": '/'+localeCodeShort+'/umbrella/api/get-users',
});
推荐阅读
- opencv - 你需要在你的机器上安装 Darknet 才能在 openCV 中使用 YOLOv4 权重和 .cfg
- arduino - lcd.setPWM(color, i) 在 ARDUINO 中有什么作用?
- caching - 使用 NewRelic 自定义缓存命中
- react-native - How to make an automatic increase in the width of the text input field depending on the number of lines?
- javascript - 如何在服务人员中获取我的配置 json 文件
- database-design - 规范化这个数据库结构
- ruby-on-rails - 如何在rails中制作重定向按钮
- wordpress - Open Site Shell 不适用于 Linux 上的 Local by Flywheel
- python - 使用 word2vec 和 gensim 查找相似词,抛出错误
- tensorflow - 如何在 Tensorflow 1.14.0 中打印冻结推理模型的节点名称?