I just need to adjust few functions in my datatable (ref Datatables ) after or before ajax response. I tried to extend the page length to 30. Its working in first page only, Eg If I have 200 rows,
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()
. If I comment pageLength: '30'
, its working fine as default(10 records per page)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.