Can't access .columns().names()
Can't access .columns().names()
vismark
Posts: 79Questions: 5Answers: 0
Following the example from this docs page, i tried to replicate it in the following code:
var table = $('#myTable').DataTable();
console.log(table.columns().names())
But I'm getting:
TypeError: table.columns(...).names is not a function
What could be gone wrong?
This discussion has been closed.
Replies
As the docs page you linked to shows, that is due to be introduced in DataTables v2 (which is still very early in development - a long way to go!).
That method is not yet available I'm afraid.
Allan
ok I'm sorry then...any other method to access column title and / or column names?
Hi @vismark ,
You could try
columns().header()
, something like this:Cheers,
Colin
Thanks colin, this is returning th's text as inserted in the dom. In my case sometimes column title and column name doesn't match, how can I retrieve them both?
To be more clear, what I do this in the init is this:
The
columns.name
option is only designed to be used as a selector (for thecolumns()
selector method). It is not used for the export data and there is no public API to get that data there I'm afraid.Allan
Hi @vismark ,
Another way to get them, is to look directly in the settings object. So
name
andtitle
will be:Cheers,
Colin
ok colin, combining both of your ansewers I should have a solution. thanks a lot!
Yeah - ideally don't use information from the settings object. It is considered to be private. it can, may and does change between versions at times, so use with caution.
If you do use it, wrap any use into a plug-in API method so if it does break in future, you can update it in just one place.
Allan