DT_RowData not working as manual suggest (sadly)
DT_RowData not working as manual suggest (sadly)
On the manual (http://www.datatables.net/examples/server_side/ids.html) page there is something like this:
{object} DT_RowData - Add HTML5 data- attributes to the TR element.
This is an object of key / value pairs which are assigned as data attributes to the TR element.
which is not true, because this will not add data-attribute="value"
to TR tag and will not allow accessing this data via $('tr').attr('data-attribute')
or finding the element by $(tr[data-attribute="value"])
. It will just add arbitrary data that will be associated with that element and will be available ONLY by $.data() function.
jquery.dataTables.js:1737
if ( data.DT_RowData ) {
$(tr).data( data.DT_RowData );
}
From jquery manula: http://api.jquery.com/data/
Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.
As of jQuery 1.4.3 HTML 5 data- attributes will be automatically pulled in to jQuery's data object. The treatment of attributes with embedded dashes was changed in jQuery 1.6 to conform to the W3C HTML5 specification.
IMHO there should be way to add real TR attributes data-{key}="{value}"
. Maybe DT_RowAttr
?
This question has an accepted answers - jump to answer
Answers
Here is a solution unless I am misunderstanding what you are trying to achieve.
Output example:
Thank you. I am doing similar thing at the moment. I just made this post to point the "problem" so maybe someone will:
Because I think feature with
$.data()
is also great and should not be changed to just setting$.attr()
;Regards!
Excellent suggestion - and the manual was certainly wrong! Thanks for pointing this out!
I've just committed the code for the suggested change, and the nightly build is now up to date with the change.
The manual for this information has been updated and I'm rebuilding the site and will deploy it in a few minutes.
Thanks for this!
Allan
WOW! What more can I say. I would love to see more developers reacting as fast as you did. Thank you!
Regards!