PDA

View Full Version : How t o save the Column configurations in GridPanel?



emmy mathew
19 Jul 2010, 4:11 AM
We have checkboxes to select/delect the columns to be shown/hide in GridPanel.How to save it so that when the user logs out and then re-login,he can find the same configuration that he had saved before logging out?

Grid Panel persist column configurations for a particular user.Any other methods other than Initializing a state provider by using getState:,applyState:


initStateEvents : function(){

Ext.grid.GridPanel.superclass.initStateEvents.call(this);

this.colModel.on('hiddenchange', this.saveState, this, {delay: 100});

this.on('bodyscroll', this.saveState, this, {buffer: 200});
}

Condor
19 Jul 2010, 4:50 AM
What is wrong with using a state provider?

(either using a CookieProvider or the HttpStateProvider from the user extensions forum)

emmy mathew
19 Jul 2010, 8:36 PM
I used the following code to save column configurations

stateful:true,
stateId:'grid',

stateEvents: ['columnresize', 'columnmove', 'show', 'hide']

getState:function(){

var o = {columns: []};

for(var i = 0, c; c = this.colModel.config[i]; i++){

o.columns[i] = {

id: c.id,

width: c.width

};

if(c.hidden){

o.columns[i].hidden = true;

}

}

var ss = this.store.getSortState();

if(ss){

o.sort = ss;

}

o.scrollState = this.getView().getScrollState();
return o;

},
applyState : function(state){

var cm = this.colModel;

var cs = state.columns;

if(cs){

for(var i = 0, len = cs.length; i < len; i++){

var s = cs[i];

var c = cm.getColumnById(s.id);

if(c){

c.hidden = s.hidden;

c.width = s.width;

var oldIndex = cm.getIndexById(s.id);

if(oldIndex != i){

cm.moveColumn(oldIndex, i);

}

}

}

}

if(state.sort){

this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);

}
this.getView().restoreScroll(state.scrollState);
},
initStateEvents : function(){

Ext.grid.GridPanel.superclass.initStateEvents.call(this);

this.colModel.on('hiddenchange', this.saveState, this, {delay: 100});

this.on('bodyscroll', this.saveState, this, {buffer: 200});
}

But when the page is refreshed the default configurations are getting displayed?

emmy mathew
19 Jul 2010, 8:55 PM
I got it worked.But I need to save it in DB or a configuration properties file.How to do it?

Condor
19 Jul 2010, 10:50 PM
Use the HttpStateProvider user extension (http://www.sencha.com/forum/showthread.php?24970-Buffering-Http-State-Provider).