View Full Version : saveState() being called on grid before state is restored

13 Dec 2013, 10:53 AM
I'm trying to get states to work on my gridpanel but I'm doing something wrong somewhere. I've set stateful and stateId for the grid and I've set stateId for all columns in the grid. I do not have any stateEvents defined.

I've confirmed that the cookie is being created and updates when I modify the grid. I can then refresh my browser page and confirm that the cookie is still set and still has my changes in it. However, after logging in to my app, the grid is displayed and for some reason saveState() fires and overwrites my cookie with the default state. This means I lose all changes and the cookie has no effect (or is possibly being loaded in after being overwritten, I can't tell). I figured this out by setting a breakpoint on the cookie in Firebug, I'm not overriding saveState(). I tried setting stateEvents to just ['click'] in the hopes of maybe preventing one of the default state events from firing but I still got the same behavior (state immediately overwritten).

What am I doing wrong? How am I triggering a saveState() as soon as the grid is displayed? Am I required to override saveState() to prevent it on the initial load?

16 Dec 2013, 1:23 PM
I'm still running into this issue. It seems the cause is the 'resize' event firing after 'viewready' and that triggers a saveState() execution, overwriting my cookie with the default state. I've tried changing the stateEvents to just ['itemclick'] and verified that it *does* update the cookie when I click on an item, but why does it also continue saving state on the default events? Shouldn't overwriting the stateEvents array blow away whatever defaults may exist?

If it helps (and I don't know how it could), this is the stack trace leading up to the saveState():

saveState() ext-all-debug.js (line 29103)
onTick() ext-all-debug.js (line 8307)
(?)() 25 (line -13667)

Kevin Jackson
19 Dec 2013, 9:13 AM
Have you looked at this example?
http://dev.sencha.com/deploy/ext-4.0.2a/examples/grid/array-grid.html. The code is not minified so it might be a starting point to compare with your code.

Otherwise, perhaps you could send a fiddle so we can look at your code https://fiddle.sencha.com/#homehttp://dev.sencha.com/deploy/ext-4.0.2a/examples/grid/array-grid.htmlHere's

Another bit of information on the subject http://druckit.wordpress.com/2013/07/11/ext-js-4-preserving-state-on-the-server-2/

19 Dec 2013, 1:34 PM
While attempting to create a code snippet for fiddle which showed what I'm doing, I think I figured out the cause of the issue. I still don't have a fix, but I think I know what pieces are relevant now.

My grid is within a card layout with "deferredRender: true". It seems if the grid is rendered with the start of the application, the 'staterestore' event fires and everything works. However, if I'm using a deferredRender and the grid is only rendered right before the user sees it, the 'staterestore' event doesn't fire. The 'resize' event fires after the grid is rendered which causes the 'statesave' event to fire and overwrite my cookie.

I'm still trying to get this to happen in fiddle to see if it's a defect or a shortcoming in my code but at least I have something to try now. I'll post the fiddle if I can reproduce the issue.

EDIT: Nevermind, that's not it. The 'render' event seems to fire at the correct time in both scenarios. Now I need to figure out why the 'staterestore' event fires in my fiddle but not in my application.

19 Dec 2013, 2:22 PM
GAH! Mystery solved! It was an issue with Sencha Architect all along.

There's no way to define an Ext.onReady in Sencha Architect so I had defined the CookieProvider in the 'launch' event handler just like in that link above. Turns out that's too late in the lifecycle so the CookieProvider wasn't defined during the 'staterestore' phase but was defined by the time I got around to a 'statesave'. Ugh.