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?

evhoeung12evhoeung12 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

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    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

  • evhoeung12evhoeung12 Posts: 7Questions: 3Answers: 1

    Thanks Allan. Any idea of when the next major release of DataTables will be? I feel that feature will be quite nice to have!

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    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

  • evhoeung12evhoeung12 Posts: 7Questions: 3Answers: 1

    Allan,

    Is this feature currently available in any release?

  • NdinhNdinh Posts: 4Questions: 2Answers: 0

    @allan It's 2019, is this feature available?

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    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:

    Hope that helps,

    Cheers,

    Colin

This discussion has been closed.