Skip to content
Advertisement

How to get name of datatable column?

I’m using DataTable 1.10.9 (from https://datatables.net). Columns for the datatable are defined at the initialization step in javascript and each column has a unique name, e.g.:

JavaScript

I know I can get the column from the table by the name I’ve given it, but I can’t seem to find how to find a column’s name from the column object. (I’m hoping it’s possible with the current state of the component.) For example:

JavaScript

What’s the proper function or property to get the name there?

Advertisement

Answer

You can retrieve the initialization options through table.settings().init() – and by that the columns definition this way :

JavaScript

When clicking on a cell / <td> you can find the column index by (best practice in case of hidden columns) :

JavaScript

An example of a click handler that alerts the corresponding column.name when a cell is clicked

JavaScript

Your every() example would be

JavaScript

demo -> http://jsfiddle.net/6fstLmb6/

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement