我使用DataTable通过serverSide模式和ajax显示我的数据 一切都很好,但分页不起作用。
您可以查看以下代码:
HTML:
<table id="table" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<td>ID</td>
<td>First name</td>
<td>Last name</td>
<td>Email</td>
</tr>
</thead>
<tbody></tbody>
</table>
使用Javascript:
$(document).ready(function () {
$('#table').DataTable({
serverSide: true,
ajax: {
url: '<?php echo base_url(); ?>folder/class/method'
},
processing: true,
scrollY: 370,
paging: true,
bJQueryUI: true
});
});
从服务器(JSON
)返回的数据如下:
{
"draw": 1,
"recordsTotal": 1208,
"recordsFiltered": 10,
"data": [
["1", "pando", "rewar", "pando@hotmail.com"],
["2", "chori", "raon", "m_chori@hotmail.com"],
["3", "Gorbat", "horiz", "horiz_555@yahoo.com"],
["4", "martin", "sokza", "martin_em5@gmail.com"],
["5", "dooz", "solda", "solda_m@gmail.com"],
["6", "maro", "meza", "r_meza@hotmail.com"],
["7", "nod", "ion", "nod_eam@yahoo.com"],
["8", "kaz", "loob", "kaz_007@hotmail.com"],
["9", "Barbara", "Elliott", "adipiscing@nonmassanon.org"],
["10", "Kendall", "Nathaniel", "ante.blandit@scelerisque.edu"]
]
}
DataTable的所有组件都可以正常工作,但不是分页。
答案 0 :(得分:0)
参数recordsFiltered
必须等于recordsTotal
,除非用户执行了搜索。有关已发送和已接收参数的详细信息,请参阅manual。
另外,请确保您在响应中返回相同的draw
参数值。在JSON response draw
参数值必须与request中draw
参数的值匹配。