Using footer callback to sum 2 columns
Using footer callback to sum 2 columns
garybrett37
Posts: 8Questions: 0Answers: 0
Hi, hope someone can assist, I am sure this question seems very basic and I apologise for that in advance. I really need to add a summary to 2 or 3 columns in my table that totals all number values & update when filtered, I have tried all sorts using the footer_callback code but simply cannot get my columns to add.
Has anyone a working example of simple addition of a column; my values are in columns 2 & 3 of the table?
ie; 20+5+25+50 = 100, once filtered to say 20 it then displays 20% of total
I tried the below which does sum column 2 but the % calc is way off
[code]
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iTotalCases = 0;
for ( var i=0 ; i
Has anyone a working example of simple addition of a column; my values are in columns 2 & 3 of the table?
ie; 20+5+25+50 = 100, once filtered to say 20 it then displays 20% of total
I tried the below which does sum column 2 but the % calc is way off
[code]
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iTotalCases = 0;
for ( var i=0 ; i
This discussion has been closed.
Replies
if (iEnd > 0) {
for (var i = 0; i < aasData[0].length; i++) {
var a = document.createElement('td');
$(a).html('');
$(nRow).append(a);
}
var columnas = [1,2,3,4,5,6,7]; //the columns you wish to add
for (var j in columnas) {
var columnaActual = columnas[j];
var total = 0;
for (var i = iStart; i < iEnd; i++) {
alert(aiDisplay[i] + ":" + [columnaActual] + ":" + aasData[i][columnaActual]);
total = total + parseFloat(aasData[aiDisplay[i]][columnaActual]);
}
$($(nRow).children().get(columnaActual)).html(total);[/code], this breaks the table, removes the search box and displays all records?
Am I missing something?
Thanks