column().title()
Get / set the title for a column.
Description
This method is used to get and set the title of a column (also settable at initialisation time by columns.title
). The title of a column is shown in the table header. It may also be used for extra functionality such as column visibility control and export data.
DataTables wraps the column header in a span
element with a class of dt-column-title
. This is done to allow the get / set operation of this method, while still allowing other HTML to be present in the header cell (e.g. inline buttons).
Of particular note is that this method can operate on multiple rows in the table header through the use of the row
parameter. This is of use when you have complex headers (multiple rows, colspan
and rowspan
). Please see the column().header()
method for details on row selection and the default selection.
Types
function column().title( [ row ] )
- Description:
This method will get the title for a column
- Parameters:
Name Type Optional 1 row
Yes This parameter can be used to control which row in the
thead
the title will be read from. The parameter is passed on tocolumn().header()
to determine which header row is to be used.- Returns:
The title for a column.
function column().title( title [, row ] )
- Description:
This method will write a string value as a column's header.
- Parameters:
Name Type Optional 1 title
No The new title to write to the table header
2 row
Yes This parameter can be used to control which row in the
thead
the title will be read from. The parameter is passed on tocolumn().header()
to determine which header row is to be used.- Returns:
DataTables API instance for chaining.
Examples
Get a column's title::
var table = new DataTable('#myTable');
var title = table.column(0).title();
// Do something with title...
Set a column's title on the default row::
var table = new DataTable('#myTable');
table.column(0).title('New title');
Set a column's title on the second row in the header::
var table = new DataTable('#myTable');
table.column(0).title('New title', 1);
Related
The following options are directly related and may also be useful in your application development.