Setting column names with HTML5 data-* attributes
Setting column names with HTML5 data-* attributes
rink_attendant_6
Posts: 16Questions: 4Answers: 1
Is there any way to use HTML5 data-* attributes to set the values of the object outlined in https://datatables.net/reference/option/columns.name?
If not, are there any plans to add this feature?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes, you can set column options using the
data-*
attributes as described here in the manual.Allan
I'm afraid it's still not clear to me how to use the data-* attributes to apply column names. For example, should it be sufficient to put a 'data-name' attribute on each <th>, or does it have to be on every <td>, or do I need to put a 'data-column-defs' attribute on the < table > with the entire array of names? I tried the first two unsuccessfully, though I would prefer to make it work with attributes on <th>.
Thanks and Best Regards,
Yes. The example I linked to shows how to use
columns.className
. The same applied tocolumns.name
. Live example.Allan
Allan, thank you for the quick reply and excellent example.
Later I'll put up a live example of what I'm trying to do that seems to be not working.
In brief, I'm trying to refer to the column name provided by the HTML5 tag while inside the 'columnDefs' block of the dataTables invocation.
My fallback is using the column index, but I can imagine that quickly becoming a maintenance nightmare.
Thanks and Best Regards,
Ah I see - the
columns.targets
option can't accept a name (since it is that option which can define a name - it couldn't find it based on that!).The
columns.targets
reference documentation shows the values that it can take.Allan