Approach to Restoring State

Approach to Restoring State

mrcrbrownmrcrbrown Posts: 2Questions: 0Answers: 0

Firstly, fantastic tool and provides a ton of functionality to projects. I've implemented a "Views" function which saves the current DataTables.state() to a database using a restful API. The DataTables is latest release with ColVis and ColReorder so the user effectively builds a version of a 30 column table and saves it with a name.

Saving works perfectly.

Loading... not so much. ColReorder is the current offender, everything else is functioning correctly. The ultimate solution would be an API call for DataTables.state(newState);

Without that, what's the best approach, as I've had failed attempts at all of them:

  1. Clear table state, build the state object, overwrite the localstorage and call datatables.save?
  2. Extend with DataTables.state.load() and use the old _fnStateLoad to copy the values in?
  3. Call each public api entry for a given state. Ie call .order() .search() etc for each of the possible elements in state?

I'd be interested to know what people would approach given the latest version and what they know works predictably.

Cheers

Replies

  • allanallan Posts: 63,771Questions: 1Answers: 10,510 Site admin

    Are you looking to be able to restore state when the table is initialised and that is the issue? As far as I am aware, that should work with ColReorder at the moment (example).

    Could you link to a page showing the issue if you are having problems with that.

    If you are looking to be able to load state from an object via the API - unfortunately there isn't an API method for that (yet - it is something that will be available in the next major version of DataTables - although that is likely some time away). You'd need to use the existing API methods to restore the state if that is something you require.

    Allan

  • mrcrbrownmrcrbrown Posts: 2Questions: 0Answers: 0

    Thanks for the insight @allan I'm attempting to restore state on an onclick event but now that you mention it my scenario is that the page is posted back as an asp.net submit. So I could focus the ColReorder to be on table initialization and then do the rest with the API.

    I'll give that a go right now, failing that I'll attempt to recreate the specific sccenarios from above with examples.

This discussion has been closed.