State persistence is lost after columns are added in the model?

State persistence is lost after columns are added in the model?

supermindsupermind Posts: 27Questions: 5Answers: 0

I'm using state persistence with stateSaveCallback and stateLoadCallback and everything works like a charm. Column ordering, search text and SearchBuilder settings works just fine. I'm happy with everything so far.

However, as my application is constantly deveoping and new columns are added in the model once in a while, state persistence data is lost, because column count is not any more the same it was when state was saved.

I understand this is suppossedly by design, but is there any way we can solve this? I mean, if new columns are added in the end of column definition (largest index), how can I get Datatables to understand that it's not an error state that the previously added state doesn't have the same amount of columns as the table currently holds. The last added colum should be visible by it's default setting (because it does not have a state saved yet) and ordered in the very end ot the table in my situation.

Anybody else having the same problem?

Replies

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    You can use stateLoadParams to reapply the save settings if the number of columns is different. Datatables won't do this because it doesn't know what changes are made Here is an example:
    http://live.datatables.net/xiwoluqu/1/edit

    If the number of columns is greater than the saved it reapplies the column order. You can see this by ordering by the Position column then clicking Run with JS. The same column order is applied because the columns haven't changed. Uncomment on or more columns the click Run with JS. The code to apply the saved settings is executed to apply the save ordering.

    You can loop through the saved columns to apply the saved visibility and search.

    Kevin

  • supermindsupermind Posts: 27Questions: 5Answers: 0

    Ok, thanks for the answer. I'll write my own middleware that adds more columns to saved settings before they're loaded if column count in the table is more than what it was when settings were saved.

Sign In or Register to comment.