Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81916

Footercallback on columns error with single row

$
0
0

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);
    }

Viewing all articles
Browse latest Browse all 81916

Trending Articles