Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2367

Add a second row to a footer

$
0
0

I have the following footer call back and I would like to add a second row,
The code below works perfectly I just need to add another row that will be some equations.
I can not for the life of me figure it out or find a working example.
Any help would be appreciated.

            "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;
                };
                var total_amount = api
                    .column(2)
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                }, 0 );
                
                for ( let i = 0; i < arr.length ; i++){
                    colValArr[i] =  api
                    .column(i + 3)
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }, 0 ); 
                }
                
                $(api.column(0).footer()).html("Total " + total_title);
                $(api.column(2).footer()).html(formatCurrency(total_amount));
                for ( let i = 3; i < arr.length + 3; i++){
                    $(api.column(i).footer()).html(formatCurrency(colValArr[i-3]));
                }
            },

Viewing all articles
Browse latest Browse all 2367