Column.name access/check?
Column.name access/check?
I am looking to access a column name without using the tableselector.
I am trying to show/hide columns at startup based on column names rather than index as the table columns are likely to change down road and I don't want to have to go back and re-index all my code.
Basically I am looping over the columns().every(...) so I have a handle to the column, but want to check it's name?
Right now I have basically the following code (which works).
if ((column.index() != 0) && (column.index() != 0) && (column.index() != 1) && (column.index() != 4) ) {
But as I said the columns have already changed on me several times and I don't want to have to keep re-indexing things, so would like to check them by name instead.
I have used the following
"columnDefs": [{ "name": "xxxx"....]
So would like to use that name in my code, something to the extent.
column.name() != "xxxx"
Obviously column("xxxx:name") does not work.
I believe I can get access to it through table handle oTable.column('xxxx:name')
Thanks
This question has an accepted answers - jump to answer
Answers
Without doubt this is something that is missing in the current API. There is no
column().name()
method but there should be and I'll be adding it in for the next version.Here is a cheeky little plug-in method which uses the internal (private!) properties of DataTables to get what you are looking for:
Example: http://live.datatables.net/datezufe/1/edit . I've called it
column().getName()
rather thancolumn().name()
since I'll be calling the built in method the latter option when it is implemented.Allan
Thanks Allan.
Thanks Allan. save my problem
+1