getting custom data attributes with data
getting custom data attributes with data
Hi
I just updated to DataTables version 2 from version 1.
Earlier when calling row().data() the data retrieved was an json object and keys was either the data-data attribute on the th or the index.
example:
html: ".....<th></th><th datat-data='template'></th>....."
calling row().data() returned: {"0":"<div>...</div>", "template":"<div>....</div>"}
version 2 returns an array of columns data, but i now miss the identifier "template" that i used earlier to get the specific data i needed.
example:
html: ".....<th></th><th datat-data='template'></th>....."
calling row().data() returns: ["<div>...</div>", "<div>....</div>"]
is it possible to set a custom data attribute on the tr or th, so i can identify the given column i wish to get the data from, something like the data-sort attribute is included in the array object.
example:
html: ".....<th></th><th datat-data='template'></th>.....<td data-sort='test'>...</td>"
calling row().data() returns: ["<div>...</div>", {"display":""<div>...</div>"","@data-sort":"test"}]
reference: https://datatables.net/reference/api/row().data()
kind regards
cbb
This question has an accepted answers - jump to answer
Answers
Can you give me a link to a page that shows the issue so I can debug it please?
Thanks,
Allan
Hi Allan
example:
https://codepen.io/coolbombom/pen/GRLjeao?editors=1111
kind regards
cbb
Hi Allan
Just to clarify, it is more a "how do i" than an issue. because i am missing a feature that was in version 1.
kind regards
cbb
Thanks for the link!
I actually don't see the
templateproperty included in the result fromrow().data()if I update it to use DataTables 1.13.11 (or 1.11.0 or 1.12.0).However, I see your point - how to get that data. If it was included in DataTables before, that was more of a happy accident than something that was planned. What to do is use
cell().node()and read the attribute from thetdelement directly.I don't seem to be able to fork your CodePen, but:
should do it.
Allan
Hi Allan
thank you for your answer. I managed by finding index of th with attribute data-name, and then getting data from row().data() with the found index.
kind regards
c_bb