{hero}

columns().header()

Since: DataTables 1.10

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:
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.