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 sum total shows the current page
i know this is bacause it loads only the current page and it cannot see the other records
now how i can show the correct sum of all pages in the footer
"yajra/laravel-datatables-oracle": "v6.11.3"
DataTables 1.10.12
PHP 5.6.15
windows 8.1
You can use something like below. Note that this was not tested but the concept should guide you to make it work:
Datatables::of($stock)
->with('total', $stock->getTotal())
->make();
$('#mytable').DataTable({
processing: true,
serverSide: true,
stateSave: true,
ajax: 'stock/data-json',
"fnDrawCallback": function() {
var api = this.api()
var json = api.ajax.json();
$(api.column(4).footer()).html(json.total);
}
});
works well
thanks
As always thanks for your help dear yajra.
Can u explain how you do that,i am new to datatables.
Working perfectly in normal condition but its not working when query have "HAVING" clause, see below -

Please give me some solution...
`I did this :
const Table = $('#foo').DataTable({
. . . . . .,
. . . . . .,
drawCallback: function(){
Table.columns(5, {
page: 'current'
}).every(function() {
var sum = this
.data()
.reduce(function(a, b) {
var x = parseFloat(a) || 0;
var y = parseFloat(b) || 0;
return x + y;
}, 0);
// console.log(sum); alert(sum);
$(this.footer()).html(sum);
});
}
});
in this case the column was column number 5`
Most helpful comment
You can use something like below. Note that this was not tested but the concept should guide you to make it work: