Problem with Cookie Provider
Top of my code:
---
var cp = new Ext.state.CookieProvider({ expires: new Date(new Date().getTime()+(1000*60*60*24*365)) });
Ext.state.Manager.setProvider(cp);
---
I am saving cookies for several page elements including:
Several combo boxes
Grid Panel
The pattern for failure is as follows:
I delete all cookies on the machine
I set the combo boxes and grid panel to new settings
I reopen the browser
On the second or third time, the cookie provider can no longer see the items in the cookie (on startup). I have verified that the cookie exists, that the items are persisting and that there is only one cookies applied by my application.
One strange thing (for me) is that the cookie provider continues to update the cookie file even if it cannot read the cookie.
I have played with the expiration date, etc. Don't know what to do next.(?) ~o)
I guess I really do not understand how the CookieProvider works.
I am using the get/set methods to set my cookies. I notice that all my values are added to the CookieProvider.state collection as soon as I set them. Once I do that, getting them is a breeze.
But when does the CookieProvider read the value from the disk? How do you force values into the state collection? They are all in the cookie - but the provider is not reading them in a timely fashion. ~o)
The issue is that when attempting to save multiple grid views, I found that I was going over the 4kb storage limit. :((
So I have a couple of requests:
Could the CookieProvider please throw an event if the character count rises above the 4kb limit. Throw me a warning.
The current state is binary - Ext JS will either read the cookie or it won't. Please throw an error saying that the cookie cannot be read (if that is the case).
My workaround for this issue is to persist the column data in IE according to the book 'JavaScript: the Definitive Guide' (David Flanagan/O'Reilly). Since I am working in a corporate environment, this will work fine for me.
There is a bug in the get/set whereby when I try to save multiple states for a single EditorGridPanel, the items cannot be retrieved. If one state object is saved, ExtJS can read it back. If 2 or more states are saved, ExtJS cannot read the items back. In fact, nothing from the cookie will come back. (An error event in this case would be greatly appreciated!)
I tried plain set/get and also wrapped the set with set(itemKey, cp.encodValue(stateObj)) and cp.decodeValue(cp.get(itemKey, '')). Neither works.
Is there a solution I can apply here?
cfg.cp.set(colState, gp.getState());
-- Where colState is the id of the column model in question and gp is a Grid Panel.
Guess what? Same problem - this appears to corrupt the cookie. The only way to get back to reading the cookie is to delete it and not save the state of the column models.
This is really frustrating.
1. Change the id's of the column to be shorter. Note: Reduces readability.
2. Remove saving widths in cookie, override applyState, getState in GridPanel. I strictly wanted to save just the hidden and moved column positions in my cookies.
My problem arose with a grid that has about 50 columns, by default the grid shows only about 10. Users can show/hide columns using the grid column heading or using a multi-select drop down.
Another option extjs developers might want to do is save to multiple cookies if size gets too large (attach 1, 2 on end and restore extra cookies into state if exists).
Other notes:
Jack mentioned in another thread to use his hybrid cookie provider in examples/state folder but once the session expires you'll lose the data unless you store the data in a database or on server in solid state by user.
So, I create an array of column models. When a user clicks on a menu item, I take the following actions:
Update the GridPanel statId with the current column model id
Call the Grid Panel saveState() method
Call the Grid Panel reconfigure() method (current store, new column model from array) to apply new view
There appears to be an issue where a cookie gets corrupted or something else if you dynamically change the state id for a grid panel and then save the state.
On a related note, the fact that the column model cannot save it's own state seems to be an issue. From an object modeling perspective, there is a lot of overlap between the Grid Panel and Column model properties and methods.
It's strange that a column model cannot persist it's own state.