Footer sum total not correct

Footer sum total not correct

bobs64956bobs64956 Posts: 18Questions: 6Answers: 0
                {
                    "data": null,
                    "render": function(data,type,row) {
                        return TotalPackageCost = parseFloat(data['ecBaseHourly'] * 40 * 52) +
                        parseFloat(data['ecVehicleCost']) +
                        parseFloat(data['ecOtherCost']) +
                        parseFloat(data['ecCash']) +
                        parseFloat(data['ecPhoneCost']) +
                        parseFloat(data['ecWorkerComp']) +
                        parseFloat(data["ecBaseHourly"] * 40 * 52 * 9.5/100);
                   }
            ],

            "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
            var Random = 0;

            pageTotal = api
                .column( 13, { page: 'current'} )
                .data()
                .reduce( function () {
                    return Random = Random + TotalPackageCost;
                }, 0);

            $( api.column( 13 ).footer() ).html(
                '$'+pageTotal.toFixed(2)
            );

Not sure what I'm doing wrong, But when trying to total the amount of the column and display it using the variable Random. The calculation does not add up. Could it be because of it being a parseFloat?

This question has an accepted answers - jump to answer

Answers

  • bobs64956bobs64956 Posts: 18Questions: 6Answers: 0
                "footerCallback": function ( row, data, start, end, display ) {
                var api = this.api(), data;
                var intVal = function ( i ) {
                    return typeof i === 'string' ?
                        i.replace(/[\$,]/g, '')*1 :
                        typeof i === 'number' ?
                            i : 0;
                };
                pageTotal = api
                    .column( 13, { page: 'current'} )
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }, 0 );
                $( api.column( 13 ).footer() ).html(
                    '$'+pageTotal
                );
    
    

    When trying to using the standard footerCallBack, no output appears as seen below.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    This thread shows how to sum the data when using columns.render.

    Kevin

This discussion has been closed.