[英]pageLength working only in firstpage - DataTable
I just need to adjust few functions in my datatable (ref Datatables ) after or before ajax response. 我只需要在ajax响应之前或之后调整我的数据表 (ref Datatables )中的几个函数。 I tried to extend the page length to 30. Its working in first page only, Eg If I have 200 rows,
我尝试将页面长度扩展为30。它只能在首页中使用,例如,如果我有200行,
rest of the pages are same like this. 其余页面是这样的。
success : function(data) {
var table=$('#datatable').DataTable() // initializing datatable
$('#datatable').dataTable().fnClearTable(); //clearing old data in every ajax response
for (var i = 0; i < data.length; i++) {
table.row.add( //adding rows
[
data[i].name,
data[i].phone
])
.draw();
}
table.destroy() // destroy existing datatable and appending following objects
$('#datatable').DataTable({
dom: 'Bfrtlip',
buttons: [ 'copy', 'excel','print', 'colvis' ],
columns: [
{name: 'name', title: 'Name'}, // Renaming Header
{name: 'phone', title: 'Phone'}
],
rowsGroup: [ // Using rowspan / grouping
'name:name',
'phone:name'
],
pageLength: '30' //page length
})
} //end of success()
If I don't destroy existing table, it shows an error message "cannot reinitialise datatable" . 如果我不销毁现有表,则会显示一条错误消息“无法重新初始化数据表” 。 I think the problem with
table.destroy()
. 我认为
table.destroy()
有问题。 If I comment pageLength: '30'
, its working fine as default(10 records per page) 如果我评论
pageLength: '30'
,默认情况下可以正常工作(每页10条记录)
Is there any way to add objects without destroying? 有什么方法可以添加对象而不破坏对象? or adding these objects while creating rows/ initializing datatable?
或在创建行/初始化数据表时添加这些对象? Or any way to soleve this problem?
或有什么办法可以解决这个问题? Thank you in advance.
先感谢您。
pageLength: 30
//页面长度应为整数:D:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.