Setting HTML5 data attributes programatically
Setting HTML5 data attributes programatically
I am trying to set the data-sort and data-filter HTML5 attributes with new data that I am fetching using AJAX. Every cell has a unique ID.
This is the code I am using:
var thiscell = table.cell(cellid);
thiscell.data(newvalue-formatted);
$(cellid).attr("data-sort", newvalue).attr("data-filter", newvalue);
However when I attempt to perform a filter later on, the cell appears to have the original values in the data-filter attribute for that cell. If I look at the actual HTML the correct values are there.
I am calling table.draw() after setting the new cell data. Is there something else I need to do to ask datatables to reload the orthogonal data into it's mapping?
This question has an accepted answers - jump to answer
Answers
Your code is 99% of the way there, but you need to call
row().invalidate()
(orcell().invalidate()
if you prefer) to tell DataTables that the data has changed. You might also need to pass the source that it should read the data from, but if you need to do that will depend upon if the table was initially Ajax or DOM loaded.Allan