How do you save and load the state of a datatable on the click of a button?
How do you save and load the state of a datatable on the click of a button?
evhoeung12
Posts: 7Questions: 3Answers: 1
I want to be able to have users have various datatable layouts. A user will be able to pull up a screen to choose which state they want loaded. I have not found any way for this to work. Ideas?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
If you call
draw()
it will trigger a state save. Currently there isn't an API method to specifically save or load a given state - that is something that is coming in the next major version of DataTables.At the moment you would need to use the API methods such as
page.len()
,order()
etc to restore the state from a state object.Allan
Thanks Allan. Any idea of when the next major release of DataTables will be? I feel that feature will be quite nice to have!
It will be 2018 sometime. I'm not entirely sure when as I've got various things being juggled that all need to fit together for it. I agree that it is a nice to have feature.
Allan
Allan,
Is this feature currently available in any release?
@allan It's 2019, is this feature available?
Hi @Ndinh and @evhoeung12 ,
You can force a state save with
state.clear()
, but there's no way to load from a selection of saved states. That said, in the OP, the user wants to choose from a list - that selection could then apply the same changes that a saved state would do, for example:search()
order()
-page()
page.len()
Hope that helps,
Cheers,
Colin