Getting title, name options, current order for column(i)
Getting title, name options, current order for column(i)
I'd like to programmatically make text that describes the filter for each column: something like Col 1 Title=Col 1 Filter Text,Col 2 Tile=Col 2 Filter Text,...
. In my previous post ("get column filter"), Allan found a bug that where dtInstance.column(idx).search() was not returning the column filter.
So, when I loop through the columns, I'd also like to get either the name or title of the column defined in the Options. But dtInstance.column(idx).title
or dtInstance.column(idx).name
returns undefined
and dtInstance.column(idx).name()
results in 'Object doesn't support property or method title/name" .
I was able to get the text datatables generates in the table header (from the options) via $(dtInstance.column(idx).header()).text()
, but should I be able to get what's defined in the options?
Also, I see that you can get a 2-d array for the ordering of the columns through dtInstance.order()
.. but should it be possible to get the ordering of an individual column, such as dtInstance.columns(idx).order()
? If I stringify that I see the large api object similiar to what I was seeing for dtInstance.column(idx).search()
Answers
There currently isn't an API method that will give you the title text code a column - although it is a jolly good idea for a plug-in.
Your suggestion of using
column().header()
is a good workaround for now.What would that return? An integer indicating where the current column is in the ordering array or
-1
if not sorting?That could also be done in a plug-in, although the logic would obviously need to be done there as that reverse logic doesn't exist in DataTables at the moment.
Allan
Thanks for the reply. OK, I guess I was think along the lines that since
table.column(idx).search()
returns the column filter, then you could also get the options associated with that column, such astable.column(idx).options('name')
. As far astable.column(idx).order()
goes, I realize that a column can have no ordering, but I was thinking it would be consistent if it returned"asc" |"desc" | ""
For the ordering It would also need to give the information about the position in the multi-column order I think for it to be complete. But yes, you could create a plug-in that would simply return a string based on the current
order()
state.Allan