footer callback summarize pos/neg

footer callback summarize pos/neg

TronikTronik Posts: 120Questions: 27Answers: 1
edited December 2016 in DataTables 1.10

Hi!

Im using footer callback for summarizing each column, but I can't get it to work when the sum is negative, for example -123.76

 footerCallback: function ( row, data, start, end, display ) {
            var api = this.api(), data;
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[^0-9.]+/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // Total over all pages
            customers = api
                .column( 1 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

I've tried putting a - sign in the regex i.replace(/[^0-9.]+/g, '')*1 but that doesn't help. Any ideas?

Basically the question is, how does this function handle summarize of negative numbers?

This discussion has been closed.