Search and Sorting doesn't work with newly created/deleted rows

Search and Sorting doesn't work with newly created/deleted rows

logan3043logan3043 Posts: 14Questions: 3Answers: 0

I'm not using the Editor extension. Rather, I create and remove rows with jquery. However, once i remove or create a row, the sorting/search function doesn't recognize the new row and once you try to search or sort, the new rows are no longer visible in the datatable and the deleted rows are shown again.

What needs to be done to make the sorting/search recognize that a new row is part of the datatable or has been removed?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited November 2019 Answer ✓

    Sounds like you are not using the Datatable's APIs to update the data. You can use APIs like:

    rows.add() or row.add() to add rows.
    row().data() or cell().data() to update data
    row().remove() or rows().remove() to remove a row or multiple rows.

    If you use something other than Datatables APIs to change the table data then Datatables won't know about the changes which results in searching and sorting to not work as expected. In this case you can use one of the invalidate() methods like rows().invalidate() or cell().invalidate(). This will tell Datatables to update its data cache with the current data.

    Kevin

  • logan3043logan3043 Posts: 14Questions: 3Answers: 0

    kthorngren, thanks for the response. Sounds like i do need to take a look at the API then and create the new rows that way. Thank you.

This discussion has been closed.