Reputation: 1606
I am using jQuery Datatables in my project and I have made "custom value" sorting available on a column by using the attribute data-sort
as described here:
https://datatables.net/examples/advanced_init/html5-data-attributes.html
Works fine. But now I am using Javascript/jQuery to update the values of these attributes, and the dataTable doesn't take into account the new values, it still sorts using the original values.
Update is done on the attribute directly as such:
$('td#myColumnId').attr('data-order', newValue);
How can I force my dataTable to re-initialise my custom sort values?
So far I have tried .draw()
and .dataTable()
but unfortunately that is not working.
I'm looking forward to a possible solution.
Upvotes: 1
Views: 6185
Reputation: 85538
You need to invalidate()
the cell(s). dataTables have no chance to know that you programmatically have changed orthogonal data (=the custom sort values) for one or more cells in a column. If you have an instance like
var table = $('#example').DataTable();
and change data-order
by
$('td#myColumnId').attr('data-order', newValue);
then invalidate
the cell / column by
table.cells("#myColumnId").invalidate();
Upvotes: 7