Accessing HTML data-* Attributes in Render Function
Accessing HTML data-* Attributes in Render Function
I'm using the example in this discussion to construct a url in a render function using HTML data-* attributes.
From my test case you can see that the render function is executed four times for each of the three targeted columns; when the type is display, type, sort and filter.
When the type is type or filter the data-search-text attribute is retrieved successfully for all three columns. For sort the render function only executes for the first column.
However, when the type is display, the one I’m interested in, the value of the data-search-text attribute is retrieved successfully for the cells in the first column, but not for cells in the second and third columns even though the render function is executed for all three columns.
Am I missing something or is this expected behaviour?
Many thanks, Steve.
Replies
As the thread you linked to mention
columns.renderis not recommended to use to access the cell's HTML contents. It's not always guaranteed that Datatables has fully processed the cells whencolumns.renderis executed. Meaning they may not be ready for thecell().nde()to be used. Instead usecolumns.createdCellorcreatedRow. I updated your test case to usecolumns.createCell.https://live.datatables.net/wagomeda/7/edit
Kevin
Thanks @kthorngren for updating my test case and pointing me in the right direction.
Bizarrely, I'm already using
columns.createdCellto add a class to the cell's row. Why it never occurred to me to use that same option to create the url I'll never know.Many thanks, Steve.