How change value of data-attr after datatable initialisation?

How change value of data-attr after datatable initialisation?

seb33gelseb33gel 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

Answers

  • seb33gelseb33gel Posts: 25Questions: 3Answers: 1

    Help please :)

  • seb33gelseb33gel Posts: 25Questions: 3Answers: 1

    Maybe it is not possible?

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16

    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:

    table.order(1,"999999999").draw();
    

    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:

             var sortOrder = $(this).attr('data-order');
             table.order(1, sortOrder).draw();
    

    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,

  • seb33gelseb33gel Posts: 25Questions: 3Answers: 1

    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 ...

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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

  • seb33gelseb33gel Posts: 25Questions: 3Answers: 1

    Thank you Allan it works fine

This discussion has been closed.