【发布时间】:2020-03-02 05:15:06
【问题描述】:
我有插件数据表 1.10,我正在尝试减少加载时间,我目前有超过 1000 条记录必须显示在表中,并且我已将其配置为分页。
问题是,当您加载页面时,您所做的是加载所有记录,一旦加载,它就会显示所有内容和页面,因为每页显示 6 条记录。
我想要或想要的是,当我加载页面时,我只需要加载当前页面的记录,如果我必须加载下一页,那么我会再次加载页面的记录。
我尝试使用“serverSide: true”,但它所做的是在不分页的情况下全部加载它们。
这实际上是我的代码:
var showcontent = baseurl+"transaction/showcontent";
var table = $('#datatablecontent').DataTable({
"responsive": true,
"processing": true,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Todos"]],
"ajax": {
"url": showcontent,
"type": "POST"
},
"autoWidth": false,
'columnDefs': [
{ 'width': 10, 'targets': 1 },
{ 'width': 5, 'targets': 2 },
{ 'width': 5, 'targets': 3 },
{ 'width': 5, 'targets': 4 },
{ 'width': 55, 'targets': 5 },
{ 'width': 30, 'targets': 6 },
{ 'width': 20, 'targets': 7 },
{ 'width': 20, 'targets': 8 , 'visible': false},
{ 'width': 40, 'targets': 9 },
{ 'width': 20, 'targets': 10 , 'visible': false},
{ 'width': 20, 'targets': 11 , 'visible': false},
{ 'width': 20, 'targets': 12 , 'visible': false},
{ 'width': 20, 'targets': 13 },
{ 'width': 20, 'targets': 14 },
{ 'width': 10, 'targets': 15 },
{ 'width': 20, 'targets': 16 , 'visible': false},
{ 'width': 10, 'targets': 17 },
{ 'width': 10, 'targets': 18 },
{ 'width': 10, 'targets': 19 },
{ 'width': 10, 'targets': 20 , 'visible': false},
{ 'width': 10, 'targets': 21 , 'visible': false},
{ 'width': 50, 'targets': 22 },
{ 'targets': 0,'searchable':false,'orderable':false,}
//{ 'targets': 1,'searchable':false,'orderable':false,}
],
"fixedColumns": true,
"iDisplayLength": 5,
"order": [[ 2, "desc" ]]
});
File php/codeigniter: transaction(controller)
public function showcontent(){
...
//Here before is the code from send data json
$output = array(
"data" => $data,
);
echo json_encode($output);
}
【问题讨论】:
标签: jquery datatables pagination