Using footer callback to sum 2 columns

Using footer callback to sum 2 columns

garybrett37garybrett37 Posts: 8Questions: 0Answers: 0
edited June 2012 in General
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

Replies

  • garybrett37garybrett37 Posts: 8Questions: 0Answers: 0
    Just to update I have now also tried [code]"fnFooterCallback": function (nRow, aasData, iStart, iEnd, aiDisplay) {
    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
  • FERCSFERCS Posts: 4Questions: 0Answers: 0
    Hi all. Sera that can help me with something. I want to use this function to add the total of a column and shown in the bottom of the table. I have no idea how. Could explain in detail? or tell me where I can get information to do so? Thank you.
This discussion has been closed.