columns().footer()
Get the footer nodes for the selected columns.
Description
This method can be used to obtain (and therefore modify) the footer cells used for multiple columns. This may be made up of th
and / or td
elements depending on the HTML for your table.
The cells returned are the cells from the first row in the table tfoot
element relating to the selected columns. If you have multiple rows in the footer that you wish to manipulate you need to use the table().footer()
method to obtain the table footer element and then use standard DOM / jQuery methods to manipulate the node.
Furthermore, the cells in the tfoot
may span multiple columns using colspan
(they can also use rowspan
, but again, only the cells in the first row will be available using this method). As such, a cell which uses colspan
may belong to multiple columns.
Note that table footers are optional in DataTables. If the columns found from the columns()
call do not have footer elements, an empty result set will be returned.
Type
function columns().footer( [row] )
- Description:
Get the footer
th
/td
cell for the selected columns.- Parameters:
Name Type Optional 1 row
Yes Since 2.0: This parameter can be used to control which row in the
tfoot
the footer cells will be read from. If undefined the first row in the footer will be used.- Returns:
DataTables API instance with header cells for the selected columns in the result set.
Example
Sum all columns which have a class of .sum
and put the sum into its footer cell:
var table = new DataTable('#myTable');
table.columns('.sum').every(function () {
var sum = this.data().reduce(function (a, b) {
return a + b;
});
$(this.footer()).html('Sum: ' + sum);
});
Related
The following options are directly related and may also be useful in your application development.