I'm now using the JSNI method I showed in the previous post along with JSON.encode and saving the resulting string.
The saved string looks like this ...
All looks good. And when I read the string back I do the following.
The object is decoded and the getAttribute() calls return the following strings, as expected.
JSOHelper.getAttribute(savedStateJSO, VIEW_STATE)
JSOHelper.getAttribute(savedStateJSO, HILITE_STATE)
The hilite state is being restored correctly now. But the view state is not. The string is passed to setViewState() which executes without error, but the ListGrid layout doesn't change to the column order that was saved.
Code:
String combinedState = JSON.encode(getCombinedState(getViewState(), getHiliteState()));
Code:
{ "viewState":"({selected:null,field:\"[\\r {\\r name:\\\"_checkboxField\\\", \\r width:28\\r }, \\r {\\ ... and on and on (the ListGrid has a lot of fields) and ending like this sortSpecifiers:[\\r {\\r property:\\\"ItemNumber\\\", \\r direction:\\\"ascending\\\"\\r }\\r ]\\r})\"})", "hiliteState":"([\r {\r \"fieldName\":\"IRET\", \r \"criteria\":{\r \"fieldName\":\"IRET\", \r \"operator\":\"greaterThan\", \r \"value\":10\r }, \r \"textColor\":\"#D50101\", \r \"cssText\":\"color:#D50101;\", \r \"id\":0\r }\r])" }
Code:
JavaScriptObject savedStateJSO = JSON.decode(savedState); String viewState = JSOHelper.getAttribute(savedStateJSO, VIEW_STATE); setViewState(viewState); String hiliteState = JSOHelper.getAttribute(savedStateJSO, HILITE_STATE); setHiliteState(hiliteState);
JSOHelper.getAttribute(savedStateJSO, VIEW_STATE)
Code:
({selected:null,field:"[\r {\r name:\"_checkboxField\", \r width:28\r }, \r {\r name:\"ItemNumber\", \r width:null\r }, \r {\r name:\"IDES\", \r width:null\r }, \r {\r name:\"IVST\", \r width .... and on and on as expected
Code:
([ { "fieldName":"IRET", "criteria":{ "fieldName":"IRET", "operator":"greaterThan", "value":10 }, "textColor":"#D50101", "cssText":"color:#D50101;", "id":0 } ])
Comment