Setting HTML5 data attributes programatically

Setting HTML5 data attributes programatically

darrenmdarrenm Posts: 7Questions: 4Answers: 0

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);;
$(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?


  • allanallan Posts: 49,585Questions: 1Answers: 7,309 Site admin

    Your code is 99% of the way there, but you need to call row().invalidate() (or cell().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.


Sign In or Register to comment.