local storage, save state
local storage, save state
https://datatables.net/extensions/keytable/examples/initialisation/stateSave
Question 1: Can this be initialized via data tags? I tried data-state-save="true" and data-keys="true" but that didn't seem to work.
Question 2: I have a table with column filters. It looks like it's restoring state correctly with the filters that I specified, but It doesn't repopulate the search params in the column filters themselves (so the user can't tell easily that it's actually a filtered list).
Answers
Question 3: how does this handle the scenario where the underlying data changes?
for example, the current table state is on page 3, filtered to only show draft status. between yesterday and today, a bunch of records were finalized and there is only 2 page of draft records. Is this going to
1. barf because page 3 doesn't exist?
2. default to page 1 because page 3 doesn't exist?
3. default to closest page because page 3 doesn't exist?
4. something else?
Q1: Using
data-state-save="true"
seems to work here:http://live.datatables.net/jiyiculu/1/edit
Q2: This is something you will need to add tot the state save data. See if this thread helps:
https://datatables.net/forums/discussion/53443
Q3: Looks like it goes to page 1. Try these steps:
http://live.datatables.net/pagefara/1/edit
- Go to page 3 or 4 or whatever
- Click
Run with JS
- the page should reload on the page you were at- Click
Add Rows
- Go to page 10
- Click
Run with JS
- Page 1 should be seen@allan or @colin can confirm this behavior.
Kevin
re Q2:
the info I want to persist/load is already saved in the state data and then loads and applies to the search. It works just fine, except that it's invisible to the user that those columns have filters that are applied. I need to wire in something to restore it on page load.
ultimately: I add the column filters after the table is instantiated, so instead of dealing with the state bugs, I actually handle it by getting the value out of the current search state when I initialize the column search boxes.
Just to let you know its not a bug that the column search input values aren't saved. The inputs are custom additions that Datatables has no knowledge of. Thats why you need to handle the updating of them in your code.
Glad you found a way to make this work.
Kevin
I know, I meant "state methods" not "state bugs" … sorry for the confusion.
it is kind of odd behavior though, since the column search itself DOES get persisted, so the table shows up filtered but with no visible filtering,
Implementing it was trivial; When I append the input box, I populate it's value based on the already restored column search. But I had already done the work to build column filters on startup for any arbitrary table.