Total over all pages for serverside datatable
Total over all pages for serverside datatable
seco
Posts: 17Questions: 6Answers: 0
Hi im using datatables 1.10
i want to show sum of current page and total pages for my serverside datatable
i use sum plugin like this
$('#mytable').DataTable({
processing: true,
serverSide: true,
stateSave: true,
ajax: 'stock/data-json',
"fnDrawCallback": function() {
var api = this.api();
// Total over all pages
var total = api.column(4).data().sum();
// Total over this page
var pageTotal = api.column(4, {page:'current'}).data().sum();
$(api.column(4).footer()).html(pageTotal + ' ( ' + total + ' total)');
}
});
the page total shows correct BUT the sum total pages show also the current page not the total !!!
and this is bacause the data is serverside processed so it ca not see the other records
now how i can get the total of all records in serverside datatable ?
thanks in advance.
This discussion has been closed.
Answers
any help to get the sum of a column when using serverside datatable ?
The client-side API is only able to sum the data at the client-side. You need to calculate the sum at the server-side using SQL or whatever data source it is that you are using.
Allan