column().header()
Get the header node for the selected column.
Description
This method can be used to obtain (and therefore modify) the header cell used for a column. This may be a th
or td
element depending on the HTML for your table.
The cell return is the one used by DataTables for adding the ordering click listener. 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.
Note that if the selector used in column()
matches more than one column, the result set will be truncated to a single column - the first one in the result set.
Type
function column().header( [row] )
- Description:
Get the header
th
/td
cell for a column.- 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:
The header cell for the selected column.
Example
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.column(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.