How change value of data-attr after datatable initialisation?
How change value of data-attr after datatable initialisation?
seb33gel
Posts: 25Questions: 3Answers: 1
Hello I look for how to change the "data-order" attribute after you add the line.
In this example by click on td class='test' changes the value of the attribute but does not affect datatable order
http://jsfiddle.net/4pry7og5/40/
can you help me?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Help please :)
Maybe it is not possible?
Hello seb33gel,
It is not entirely clear what you are asking, but in order to change the order of the datatable you should use the already created variable for your datatable and call the order() function followed by the draw() function to trigger the re-ordering.
So in your fiddle you change that line to:
The part that is unclear to me is what are you trying to sort on? the value of the data attribute? Because you can achieve that as such:
But this would always sort that column in descending order and clicking it again would not change the order. So again, I am not sure what you want to achieve.
Hope this helps,
Hello Ashbjorn thank you for reply
I will try to be clearer.
http://jsfiddle.net/4pry7og5/43/
in the first example if you click on the number of greg "40" it will become 41 and then a second time 42.
When I change the value of a cell, the order changes depending.
http://jsfiddle.net/4pry7og5/45/
In the 2nd example I use data-order attributes and I would do the same.
I hope to be a little clearer ...
You need to invalidate DataTables' cache of the original value after you change it. See
row().invalidate()
. Otherwise it will use the old cached value (for speed).Allan
Thank you Allan it works fine