Print option in jquery datatable--would like to print the final total of a column in the footer
Print option in jquery datatable--would like to print the final total of a column in the footer

Currently only the first page total is printed in the footer.
code used
footer:true,
exportOptions: {
modifier: {
order: 'index', // 'current', 'applied','index', 'original'
page: 'all', // 'all', 'current'
search: 'none' // 'none', 'applied', 'removed'
},
columns: [0, 1, 2, 3, 4]
}
footer call back is
footerCallback: function( tfoot, data, start, end, display ) {
var api = this.api();
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
total = api
.column(4)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0)
pageTotal = api
.column(4, { page: 'current' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
$(api.column(4).footer()).html(
pageTotal + ' (' + total + ' total)'
);
}
the values displayed in the page are correct. But on print option only the first page total is displayed in the footer.
This discussion has been closed.
Answers
You've got
.column(4, { page: 'current' })
in your code - so it'll sum those values on the current page. If you remove{ page: 'current' }
, it should sum all pages.Colin