Footercallback on columns error with single row
Footercallback on columns error with single row
Works just fine if number of rows is 2+.
If number of rows is 1, column totals are correct, but " bigTotal " is wrong...instead of $45.00, I get $4,500.00
    "footerCallback": function ( row, data, start, end, display ) {
        var api = this.api(), data;
        var bigTotal = 0;
        // 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
        totalCash = api
            .column( 2 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            } );
            bigTotal = bigTotal + totalCash;
        totalCash = Number(totalCash).toLocaleString("en-US", {style:"currency", currency:"USD", minimumFractionDigits: 2});
        totalCheck = api
            .column( 3 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            } );
           bigTotal = bigTotal + totalCheck;   
        totalCheck = Number(totalCheck).toLocaleString("en-US", {style:"currency", currency:"USD", minimumFractionDigits: 2});
        totalCredit = api
            .column( 5 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            } );
        bigTotal = bigTotal + totalCredit;
        totalCredit = Number(totalCredit).toLocaleString("en-US", {style:"currency", currency:"USD", minimumFractionDigits: 2});
        totalPaypal = api
            .column( 6 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
           } );
        bigTotal = bigTotal + totalPaypal; 
        totalPaypal = Number(totalPaypal).toLocaleString("en-US", {style:"currency", currency:"USD", minimumFractionDigits: 2});
        //DIVs inside footer th 
        $("#totalCash").text("    " + totalCash);
        $("#totalCheck").text("    " + totalCheck);
        $("#totalCredit").text("    " + totalCredit);
        $("#totalPaypal").text("    " + totalPaypal);
        bigTotal = Number(bigTotal).toLocaleString("en-US", {style:"currency", currency:"USD", minimumFractionDigits: 2});
        $("#bigTotal").text("    " + bigTotal);
    }
                This discussion has been closed.
            
Replies
According to the reduce() MDN docs the follwoing happens with one value:
Your variables like
totalCashend up a string with values like$45.00.bigTotalis probably a concat string of your columns. Try changing to something like this for each column:Kevin
That worked...thanks.