columns().titles()
Get / set the title for multiple columns.
Description
This method is used to get and set the titles of multiple columns (which are 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).
Types
function columns().titles( [ row ] )
- Description:
This method will get the titles for the selected columns
- 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 titles for the selected columns.
function columns().titles( title [, row ] )
- Description:
This method will write a string as the title for multiple columns.
- Parameters:
Name Type Optional 1 title
No The new title to write to the table header for selected columns. This string will be used for all columns selected and for this reason, this overload is of limited use. If you wish to use a different string for each column, use
column().title()
and iterate over an array or other source of the column titles.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.
Example
Get the titles for all columns::
var table = new DataTable('#myTable');
var titles = table.columns().titles();
// Do something with titles...
Related
The following options are directly related and may also be useful in your application development.