Sum of the columns
Sum of the columns
cmplus
Posts: 65Questions: 13Answers: 0
Hello, I inserted this code to add the columns, it works but I have a problem, I would like to exclude the columns containing the percentages from the sum and I would like to be able to also add the numbers that I have in the table with a divisor point, can someone help me to change the code?
Aug 516 1,465,334
April 368 280.075
December 0 1,166,294
February 398 202.608
January 570 225.596
June 569 756.230
July 260 1,227,357
May 580 407788
March 458 247.697
November 0 1.148.931
Total No. 3,719
drawCallback: function () {
var api = this.api();
var sum = 0;
var formated = 0;
$(api.column(0).footer()).html('Totale');
for(var i=1; i<=3;i++)
{
sum = api.column(i,).data().sum();
formated = parseFloat(sum).toLocaleString('it');
$(api.column(i).footer()).html('NĀ° '+formated).toFixed(2);
}
},
This question has an accepted answers - jump to answer
Answers
I would look at assigning a class to the columns you want to sum. Then use
columns().every()
to loop through those columns using the classname as thecolumn-selector
.Better might be to use the
footerCallback
as shown in this example.Kevin
Thanks for the reply but the example link doesn't work
I fixed the link. Here it is:
https://datatables.net/examples/advanced_init/footer_callback.html
Kevin