clarent
clarent

Reputation: 347

How to use Ext.state.Manager with localStorage instead cookies?

Ext JS Ext.state.Manager has only Coockie provider. Cookie can hold only 4096 bites and if my grid or tree has many columns - it overflow 4096 bites and cant save state. one else issue - every request to server sends all cookies in request, so Apache or anoter web server can not permit huge cookies.

I want to use Provider to save data in localStorage. Is any ready solution? Or I have to write it ?

Upvotes: 2

Views: 1475

Answers (2)

cachius
cachius

Reputation: 1906

The class Ext.state.LocalStorageProvider has been added to ExtJS in Ext JS 4 Beta 1 released on March 30, 2011. See original Docs and Implementation and current Docs and Implementation as of March 11, 2022.

Ext.state.Manager.setProvider(new Ext.state.LocalStorageProvider());

Upvotes: 0

clarent
clarent

Reputation: 347

Here is workaround that I use for now, but may be any more complex solution?

Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
    setCookie : function(name, value){
       var me = this;
       localStorage.setItem(me.prefix+name,me.encodeValue(value));
    },
    clearCookie : function(name){
        var me = this;
        localStorage.removeItem(me.prefix+name);
    },
    readCookies : function(){
        var prefix = this.prefix,
            len = prefix.length,
            cookies = {};
            keys = Object.keys(localStorage),
            i = 0;
        for (; i < keys.length; i++) {
            console.log(keys[i].substring(0, len));
            if (keys[i] && keys[i].substring(0, len) == prefix){
            cookies[keys[i].substr(len)]= this.decodeValue(localStorage.getItem(keys[i]));
        }
    }
        return cookies;
    }
})); 

Upvotes: 4

Related Questions