Load state after api is available
Load state after api is available
I want to store datatable's state in database. It is possible and works perfect, when I use stateLoadCallback and stateSaveCallback. But as soon as another column is added to datatable the state is ignored and replaced by the default one.
So I decided that if I save state with column names not indexes then I can convert it to indexes when loading and back to names when saving. But unfortunately the api is not available on stateLoadCallback yet, so the conversion is not possible. Can you please suggest some workarounds?
Answers
At the moment you would need to call
page()
,page.len()
, etc as appropriate to set the state based on the state saved object. There currently is no API method that will restore the state at an arbitrary time after initialisation. That is something that will be added for the next major version.Allan
I would like to load a state object from a URL, so that people can share permalinks to specific views of the table.
For example, this URL:
It would be great if someone could copy and paste that URL and share it with someone else so they see exactly the same data in the table.
This has at least one problem, I believe: On a table with many columns, you may exceed the number of characters allowed in a browser's location bar. There are also some properties that don't need to be here. For example, if there is no search applied on a column, does that column need to be present in the
columns
array?How I did that
$.address
is a plugin for jQuery that manipulates the "hash bang" style of URL hashes.This isn't the only way to solve the "permalink" need, I bet, but the one I was experimenting with today.
For permalinks you might be better using the approach introduced in this blog post. Assuming the data in the table hasn't changed, it would work nicely (the state saving method would also require the data to not change).
Yes. It is index based. If you miss a column the others would be offset by one.
Allan