PDA

View Full Version : [2.x][CLOSED] GridPanel applyState: Hidden doesn't hide column header



durlabh
11 Aug 2008, 9:18 AM
I'm not sure whether others have noticed this as well or not. In couple of my cases, I noticed that when a column is hidden in the stored state and state is restored on a rendered grid, grid headers remain visible while content is hidden. I propose the following fix:



Ext.grid.GridPanel.override({
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.width = s.width;
var oldIndex = cm.getIndexById(s.id);
cm.setHidden(oldIndex, s.hidden);
if(oldIndex != i){
cm.moveColumn(oldIndex, i);
}
}
}
}
if(state.sort){
this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);
}
}
});

brian.moeskau
23 Sep 2008, 10:30 PM
I'm assuming you are on an older version. That code has had this since at least 2.1 and seems to work fine:


if(c){
c.hidden = s.hidden;
c.width = s.width;

durlabh
24 Sep 2008, 5:10 AM
Brian, column model does change but there are no updates on the screen in this case. So, is it by design that we must call grid.getView().refresh(true)?

Condor
24 Sep 2008, 5:24 AM
@brian:

You assume that applyState is only called with the state from the state manager when the component is created.

However, several people use getState and applyState to save and restore column layout (e.g. a "Restore columns" button).

This means that applyState can also be called when the grid is already rendered.

Slb
14 Sep 2009, 2:20 AM
i have given Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
and " stateful: true," to save the columns of grid in cookies and get those. I would like to have a button for the grid which will restore all the columns. Can you pls guide me how can i use the applyState in the restore buttton?