Calculate Total of one column
Calculate Total of one column
Hello, i use the footerCallBack to calculate the Total based in Points of Exchange, I have a table width products, each row have a checkbox to select and send to server. When I select any checkbox, I'd like to that total will be updated. Course, using the api of DataTables. Some Ideas?.
Thanks.
<code>
"footerCallback" : function() {
var total;
var pageTotal;
var oTable = this;
var api = oTable.api();
var data;
// Remove the formatting to get integer data for summation
var intVal = function(i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
data = api.column(7).data();
total = data.length ?
data.reduce(function(a, b) {
return intVal(a) + intVal(b);
}) :
0;
// Total over this page
data = api.column(7, { page: 'current' }).data();
pageTotal = data.length ?
data.reduce(function(a, b) {
return intVal(a) + intVal(b);
}) :
0;
// Update footer
$(api.column(7).footer()).html(
'Puntos ' + pageTotal + ' ( Puntos ' + total + ' total)'
);
}
</code>