Author Topic: loadState using State Parameter  (Read 4041 times)

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
loadState using State Parameter
« on: September 15, 2020, 06:16:52 pm »
Saving/Loading from from browser storage works great, but when I send in the state using state parameter, it's ignoring this and just loading the browser stored state. Any suggestions?
               
var temp = "{'colModel':[{'dataIndx':'res','width':20}.......}";
$gridMain.pqGrid("loadState",temp);

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #1 on: September 16, 2020, 04:16:25 pm »
Please check the syntax of method call:

Code: [Select]
$gridMain.pqGrid("loadState", { state: temp });

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #2 on: September 17, 2020, 06:20:00 pm »
I'm getting an error with using my state parameter. I'm guessing it's not formatted correctly.
I got the json string using saveState, and replaced the double quotes w/singe quotes and use that as my param. Any ideas why this doesn't work?

"{'colModel':[{'dataIndx':'res','width':283},{'dataIndx':'proj','width':275},{'dataIndx':'id','width':240,'hidden':true},{'dataIndx':'projectuid','width':240,'hidden':true},{'dataIndx':'resourceuid','width':240,'hidden':true},{'dataIndx':'Notes','width':200,'filter':{},'hidden':true},{'dataIndx':'JO Base Alloc','width':200,'filter':{},'hidden':true},{'dataIndx':'JO Remaining Alloc','width':200,'hidden':true},{'dataIndx':'RBS','width':200,'hidden':true},{'dataIndx':'CCDivF','width':200,'hidden':true},{'dataIndx':'CCDivH','width':200,'hidden':true},{'dataIndx':'CostCenter_','width':200,'hidden':true},{'dataIndx':'EmployeeNumber','width':200,'hidden':true},{'dataIndx':'JO','width':59},{'dataIndx':'JOSO','width':69},{'dataIndx':'JOGROUP','width':200,'hidden':true},{'dataIndx':'JODivision','width':200,'hidden':true},{'dataIndx':'01/01/20~b8f70726-2c22-4c69-b48c-da7ae88d6837','width':70},{'dataIndx':'Range Total','width':70}],'datestamp':1600345733432,'height':600,'width':'100%','freezeRows':0,'freezeCols':4,'groupModel':{'dataIndx':[],'collapsed':[false]},'pageModel':{'curPage':1,'rPP':10},'sortModel':{'sorter':[{'dataIndx':'res','dir':'down'}]}}"

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #3 on: September 17, 2020, 08:13:05 pm »
Does it work without replacement of the double quotes w/singe quotes?

Could you please share a jsfiddle.

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #4 on: February 24, 2021, 06:40:59 pm »
Yes, it actually does. Thank you!

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #5 on: June 28, 2021, 08:58:48 pm »
I'm using multiple grouping levels in my grid. Is there a way to save the expand/collapse state of a row in the savestate method? If not is there a strategy I could implement to achieve this?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #6 on: June 28, 2021, 09:36:04 pm »
Please read about nodeClose property of groupModel. https://paramquery.com/pro/api#option-groupModel

and add it in stateKeys property:

Code: [Select]
stateKeys: { groupModel: ['dataIndx', 'collapsed', 'grandSummary', 'nodeClose'] },

Example of usage:

https://paramquery.com/pro/demos/grid_state

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #7 on: June 29, 2021, 05:04:33 pm »
Thank you. That works. However, there's a scenario where I'm selecting a new grid state from a dropdown list without reloading the page and it's not working. Any ideas why?

                var obj = document.getElementById("selViews");
                var gState = obj.options[obj.selectedIndex].getAttribute('rpmGridState')
                const search = '\\"';
                const replaceWith = '"';
                const result = gState.split(search).join(replaceWith);
                success = $gridMain.pqGrid("loadState", { state: result });
                $gridMain.pqGrid('option', 'title', "Current View: " + obj.options[obj.selectedIndex].text);
                $gridMain.pqGrid("refreshView");

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #8 on: June 29, 2021, 11:30:59 pm »
Please remove the last line and recheck:

Code: [Select]
$gridMain.pqGrid("refreshView");

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #9 on: June 30, 2021, 01:41:43 am »
Works! Thanks. If I have a column filter applied to one viewstate and change to another viewstate (w/no filter), the filter remains. Any ideas on how to remove this for the viewstate which doesn't have a filter applied?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #10 on: June 30, 2021, 10:58:41 am »
Please clear the previous filtering in grid before load another state:

Code: [Select]
grid.reset({filter: true});

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: loadState using State Parameter
« Reply #11 on: June 30, 2021, 09:03:03 pm »
Thanks, that works great.
If I try to load state using this: result = $gridMain.pqGrid("loadState", { state: result });
and a recently added field in the grid doesn't exist in the state, I get this error: Uncaught TypeError: Cannot read property 'dataIndx' of undefined

What's the best way to either avoid this error or get the "result" var back, in order to let the user know that the state is old and doesn't contain 1 or more grid fields.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: loadState using State Parameter
« Reply #12 on: July 01, 2021, 09:05:33 am »
That shouldn't be a problem ( error ), which version of grid are you using? Could you please share a jsfiddle as well.