columns.name
Set a descriptive name for a column.
Description
When working with DataTables' API, it is very common to want to be able to address individual columns so you can work with them (you wish to sum the numeric content of a column for example). DataTables has two basic methods of addressing columns:
- As a column index (automatically assigned when the table is initialised)
- With a name - assigned using this option!
This can make working with columns in the API very easy - for example to access the data from the column named location
you would use table.column( 'location:name' ).data()
- append the string :name
to indicate to DataTables that it should perform a column name selector operation. For more information about column selectors, please see the column()
documentation.
Type
This option can be given in the following type(s):
Examples
Setting column names with columnDefs
:
new DataTable('#myTable', {
columnDefs: [
{ name: 'engine', targets: 0 },
{ name: 'browser', targets: 1 },
{ name: 'platform', targets: 2 },
{ name: 'version', targets: 3 },
{ name: 'grade', targets: 4 }
]
});
Setting column names with columns
:
new DataTable('#myTable', {
columns: [
{ name: 'engine' },
{ name: 'browser' },
{ name: 'platform' },
{ name: 'version' },
{ name: 'grade' }
]
});
Related
The following options are directly related and may also be useful in your application development.