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
Zac
Posts: 5Questions: 0Answers: 0
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?
[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?
This discussion has been closed.
Replies
Allan