Add second footer row showing totals for filtered rows and minding hidden columns

Add second footer row showing totals for filtered rows and minding hidden columns

ZacZac Posts: 5Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
Hi, I'm currently able to build up an array of totals for all of my filtered rows, using the underscore:

[code]
var totals = ['Filtered Totals:'];
var rows = table._('tr', { "filter": "applied" });
$(table.fnSettings().aoColumns).each(function (index, value) {
var col = $(this.nTh);
var total = null;
if (col.data('total-type') == 'sum') {
total = 0;
for (var i = 0; i < rows.length; i++)
{
total += parseInt(rows[i][index]);
}
}
totals.push(total);
});
[/code]

However, with this array of new values I can't figure out how to add a new tfoot row.

I don't want to just append with jQuery as our system also allows dynamic hiding of columns (e.g. for smaller screens) so we would like datatables to be in control of the new footer row (in the same way that it takes care of hiding columns in the existing footer row)

Any ideas?

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Add the extra footer row before you initialise the table using standard jQuery / DOM methods and DataTables will recognise it and control it the ay it does the header and footer (i.e. column visibility, when using the API, will still work).

    Allan
This discussion has been closed.