Author Topic: save multiple states of grid in Localstorage  (Read 6058 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
save multiple states of grid in Localstorage
« on: March 06, 2016, 02:48:45 am »
Hi

Im using the saveState and loadState functions which works fine. Now I would like to have the possibility to save and load different states.
Example: I save current state with a user input name which then will be available in a loadstate dropdown. This mean the user can save states and then choose to load a certain state. Preferably also with the possibility to rename or delete a state.

Would that be possible and how could a solution for that look like?

Thanks.
« Last Edit: August 24, 2017, 05:02:54 pm by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Localstorage (saveState and loadState)
« Reply #1 on: March 07, 2016, 12:43:54 pm »
saveState( { save: false } ) returns a string which you can name and save it in an object.

Code: [Select]
var saveStates = {
  key1: saveState1,
  key2: saveState2,
  key3: saveState3,
  ...
}

In the dropdown add the name of states as options

When the user selects key1, call loadState( { state: saveStates[ 'key1' ]  }) to load corresponding state.
« Last Edit: March 07, 2016, 12:50:58 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Localstorage (saveState and loadState)
« Reply #2 on: August 23, 2017, 06:17:48 pm »
I save different states to local Storage with different keys.
How can I read these and populate dropdown on page load?

http://jsfiddle.net/rcw7114y/

Thanks.



« Last Edit: August 23, 2017, 07:53:06 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Localstorage (saveState and loadState)
« Reply #3 on: August 24, 2017, 04:40:38 pm »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Localstorage (saveState and loadState)
« Reply #4 on: August 24, 2017, 04:52:01 pm »
Thanks. Would it be possible to populate the drop down with all states available from local storage on page load?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Localstorage (saveState and loadState)
« Reply #5 on: August 24, 2017, 04:59:01 pm »
yes, please check this

http://jsfiddle.net/rcw7114y/2/

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #6 on: August 25, 2017, 01:06:43 am »
Having an issue...after you enter name of the state (new, does not exist) the select visible column gets "destroyed"...?

http://jsfiddle.net/rcw7114y/3/
« Last Edit: August 25, 2017, 01:08:22 am by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #7 on: August 25, 2017, 02:14:38 pm »
Also, been trying to add a text instead of the localStorage key name to be displayed in the dropdown...how can I add the text when pushing the item to options array?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #8 on: August 25, 2017, 03:01:24 pm »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #9 on: August 25, 2017, 07:59:22 pm »
Great, thanks.
If I would like to load state from qs, like: pq.html?state=statename, where should I execute the loadstate?

Have something like this:

Code: [Select]
var state = localStorage.getItem(prefix() + qsState);
          this.loadState({
            state: state
          })

No success though and can I load it by a more efficient way (The dropdown should be selected with the state from qs also)?

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #10 on: August 28, 2017, 02:44:10 am »
Solved.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #11 on: August 28, 2017, 06:50:43 pm »
Afraid not  :)
Having problems with pqSelect filters
The information is correct in the local storage value. Seems it doesn't get refreshed when I execute the loadstate for qs load?

 
Code: [Select]
create: function() {
     
    var state = localStorage.getItem(prefix() + qsState);
           
         this.loadState({
            state: state
          })

refreshToolbar(this);
$("#loadState").val(qsState);
}
« Last Edit: August 28, 2017, 07:48:50 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #12 on: August 29, 2017, 12:53:45 pm »
To clarify, I use ?state=state as qs and want the state to be loaded...and it does but the filters with pqselect does not get updated...

http://jsfiddle.net/fwmLo4jd/1/
« Last Edit: August 29, 2017, 12:57:55 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #13 on: August 29, 2017, 06:48:52 pm »
Let's make the filters work with localStorage first as this post is about localStorage

Please check this: http://jsfiddle.net/mo6p4uvt/

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: save multiple states of grid in Localstorage
« Reply #14 on: August 29, 2017, 06:58:05 pm »
Great, thanks.
« Last Edit: August 29, 2017, 07:26:21 pm by queensgambit9 »