StateRestore states being overwritten by second table on same page/path

StateRestore states being overwritten by second table on same page/path

ctmlctml Posts: 19Questions: 6Answers: 0
edited January 5 in Bug reports

Link to test case:
https://jsfiddle.net/6mzwosvd/6/

Description of problem:
State save does not appear to be using the table dom ID (my best guess) to uniquely save states used in stateRestore across different tables on the same page. When two tables are on a page, changing the state of table 2 (creating/deleting/updating) overwrites the available states in table 1 despite them having different dom id's (and vice versa). I tried to override the state save/load callbacks and specifying the keys to ensure they were unique but it didn't seem to have an effect. I also tried using session storage by setting the saveDuration to -1 but no change.

To reproduce just reload the page after creating a new date (or deleting one) and of course leave snippet as is else page path changes and all states will be lost.

https://datatables.net/reference/option/stateSave

This question has accepted answers - jump to:

Answers

  • sandysandy Posts: 805Questions: 0Answers: 216

    Hi @ctml ,

    Thanks for pointing this out. I've raised an issue internally (DD-2423 for my reference) and will report back here when there is an update.

    Thanks,
    Sandy

  • ctmlctml Posts: 19Questions: 6Answers: 0

    Thanks @sandy , if you happen to be aware of any workarounds in the meantime please let me know =) Sadly I've had to remove the extension for now as most of my pages have two tables.

  • sandysandy Posts: 805Questions: 0Answers: 216
    Answer ✓

    Hi @ctml ,

    That should be the issue fixed now. This will be available in the next StateRestore release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.

    Thanks,
    Sandy

  • ctmlctml Posts: 19Questions: 6Answers: 0

    Thanks @sandy , you're a rock star!

  • ctmlctml Posts: 19Questions: 6Answers: 0

    @sandy I tried nightly and still encounter the issue. Below is an updated fiddle with nightly js for state restore.

    https://jsfiddle.net/1gfbojtd/

    PS: The stateRestore header is labeled as "Select" (duplicate) in nightly downloads and the second js link is not provided for the styling options unlike other extensions.

    https://datatables.net/download/nightly

  • sandysandy Posts: 805Questions: 0Answers: 216

    Hi @ctml ,

    Sorry but it looks to be working for me!


    You might have to break the cache on the script tag that pulls in the nightly build - try adding ?ausdbvcaubv to the end of the url.

    Thanks,
    Sandy

  • ctmlctml Posts: 19Questions: 6Answers: 0

    That seems to have helped, however there is still a conflict in the individual states themselves.

    1. Create a new state in table 1
    2. Refresh and confirm table 1 states and tables 2 states look good
    3. Create a new state in table 2
    4. Refresh and the first state is now gone from table 1 but the new one exists in table 2
  • ctmlctml Posts: 19Questions: 6Answers: 0

    Hi @sandy, here is an updated fiddle using the 1.1 release. Thanks

    https://jsfiddle.net/kr1p037u/

  • sandysandy Posts: 805Questions: 0Answers: 216

    Hi @ctml ,

    Thanks for pointing this out! I've reopened the issue I mentioned above and will report back here when there is an update.

    Thanks,
    Sandy

  • sandysandy Posts: 805Questions: 0Answers: 216
    Answer ✓

    Hi @ctml ,

    That should be the issue fixed now as you can see at this example. This will be available in the next StateRestore release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.

    Thanks,
    Sandy

  • ctmlctml Posts: 19Questions: 6Answers: 0

    Thank you @sandy! Confirmed working with latest nightly, cheers.

Sign In or Register to comment.