columns().header()
Get the header node for the selected columns.
Description
This method can be used to obtain (and therefore modify) the header 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 ones used by DataTables for adding the ordering click listener - i.e. one cell for each column that was matched by the selector. If you have multiple cells in a header (i.e. multiple rows), which one DataTables uses as the primary header cell is defined by the orderCellsTop
option.
Type
function columns().header( [row] )
- Description:
Get the header
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
thead
the header cell will be read from. If empty DataTables will use the primary header cell (orderCellsTop
).- Returns:
DataTables API instance with header cells for the selected columns in the result set.
Examples
Remove a class from columns with that class:
var table = new DataTable('#myTable');
table
.columns('.highlight')
.header()
.to$()
.removeClass('highlight');
Alert the name of the column for a cell that was clicked on:
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'td', function () {
var idx = table.cell(this).index().column;
var title = table.columns(idx).header();
alert('Column title clicked on: ' + $(title).html());
});
Related
The following options are directly related and may also be useful in your application development.