Remember table col sort between renders

Remember table col sort between renders

StanAccyStanAccy Posts: 31Questions: 5Answers: 0

I have a Datatable which displays data based on the selections of another element on the page (basically a list of checkboxes). When the user changes the checkbox selections, the datatable gets re-rendered (new data retrieved via AJAX and the datatable programmatically redrawn with the data for the selected elements).

Is there a built-in way for the Datatable to remember what the user selected sort was so that as the user is checking/unchecking boxes in other parts of the page, the Datatable shows a user-selected sort of the data?

If no built in way, is there a way to listen to Datatable's selected sort option, so I could reset the sort after the table is redrawn?

When the table is being draw, im currently setting it to destroy:true. Maybe there's a better way to handle this data change?

This question has an accepted answers - jump to answer

Answers

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    stateSave:true seems to be what I want!

  • allanallan Posts: 59,813Questions: 1Answers: 9,685 Site admin
    Answer ✓

    I'd suggest not destroying the table, unless the data structure changes. If it is the same structure just different data based on the user's input, then use clear() to delete the old data and rows.add() to add the new data.

    Exactly how this would de done will depend upon how you are loading the data in, but if you can reuse the table, I would suggest doing so.

    Allan

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Thnks

Sign In or Register to comment.