Dynamically update table content and then reorder table?

Dynamically update table content and then reorder table?

netpresentnetpresent Posts: 4Questions: 2Answers: 0

I have a large table in which one columns shows a percentage (as a formatted number, eg -8.41). The TD containing it also has a data field with the full detail number, e.g. data-sort='-8.4128465'.

I get new numbers every 10 seconds through ajax and update both the data-sort attribute and the TD content. After updating all percentages I want to automatically reorder the whole table. I am trying the following, but nothing seems to happen (no error message either though):

const order = datatable.order(); datatable.order(order).draw();

Any ideas on how I can make this work would be very much appreciated.

Cheers,
Jeroen

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    If you are not using Datatables APIs to update the table data then see this FAQ for some options. If you still need help please post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • netpresentnetpresent Posts: 4Questions: 2Answers: 0

    Thanks Kevin. I made this simple page with only 1 table, just to replicate the issue. To see the problem, order on the first '24h %' column and then refresh. Strangely enough, the ZEC row is already out of order even before the first dynamic update comes, and even manually ordering on the same column again does not do what I would expect.

    https://playak.com/tmp/dyndatatables.php?dummy=4

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    If I call row().data() to get the values for the ZEC row, I'm seeing mostly zeros:

    This suggests the data is being updated behind DataTables's back, so it has no idea the values have changed. Either call rows().invalidate() to force a refresh, or update the rows through the API with row().data(),

    Colin

This discussion has been closed.