PDA

View Full Version : [INFOREQ] [OPEN-1355] GridPanel restore state bug



vladsch
28 Sep 2010, 1:23 AM
Hi,

If set id for a grid's column then grid doesn't restore the state because setState method of the ColumnModel cannot find the column. I guess that 'this.config' must be replaced by 'this.lookup'

Original method


setState : function(col, state) {
Ext.applyIf(this.config[col], state);
}


Fixed version


setState : function(col, state) {
Ext.applyIf(this.lookup[col], state);
}

Jamie Avins
4 Oct 2010, 8:50 AM
Wouldn't that change the API to use columnId instead? lookup is a just a hash.

vladsch
4 Oct 2010, 11:36 AM
Hi,

Thanks for the reply.
Just see the following sample
http://dev.sencha.com/deploy/ext-3.3.0-rc/examples/grid/array-grid.html

CookieProvider is used in that example but if you try to hide Company column (it is only column which has predefined id) and refresh the page then column will be visible

hikarusai
15 Oct 2010, 2:00 AM
This is still a problem in the 3.3.0 release. The "Stateful Array Grid Example" pointed out by vladsch illustrates the problem with the "Company" column.

DelSolo
21 Oct 2010, 11:59 PM
I got similar problem with sorting after restoring the state and solved it this way (3.3.0):

Original Code (Ext.grid.ColumnModel):


setState : function(col, state) {
state = Ext.applyIf(state, this.defaults);
Ext.apply(this.config[col], state);
}


Fix:


setState : function(col, state) {
Ext.apply(this.config[col], state);
}

shallow
16 Nov 2010, 4:56 AM
The bug exists in ExtJs since 3.2.2.
In ExtJs 3.3.0, in Ext.grid.GridPanel we have:



applyState : function(state){
var cm = this.colModel,
cs = state.columns,
store = this.store,
s,
c,
oldIndex;

if(cs){
for(var i = 0, len = cs.length; i < len; i++){
s = cs[i];
c = cm.getColumnById(s.id);
if(c){
//###########################
// setState expects an INDEX[Number] as its first arg but it gets an ID[String]
//###########################
cm.setState(s.id, {
hidden: s.hidden,
width: s.width
});
oldIndex = cm.getIndexById(s.id);
if(oldIndex != i){
cm.moveColumn(oldIndex, i);
}
}
}
}
if(store){
s = state.sort;
if(s){
store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
}
s = state.group;
if(store.groupBy){
if(s){
store.groupBy(s);
}else{
store.clearGrouping();
}
}

}
var o = Ext.apply({}, state);
delete o.columns;
delete o.sort;
Ext.grid.GridPanel.superclass.applyState.call(this, o);
},

mikecar
18 Nov 2010, 2:04 AM
so, what is the recomended fix ? I just came across this, trying to migrate an app from 3.1.0 to 3.3.0.

mikecar
19 Nov 2010, 2:56 AM
I confirm this bug, and I am amazed nobody has fixed it yet!
I tried this fix, and it seems to work fine:


Ext.grid.ColumnModel.prototype.setState=function(col, state){
state = Ext.applyIf(state, this.defaults);
Ext.apply(this.lookup[col], state);
}

dizor
27 Nov 2010, 11:33 PM
Any good solution for this? I have problem that when i have hidden columns on grid, enable it and customize column order - when restored align is no good.

mikecar
29 Nov 2010, 2:21 AM
The solution I posted does not work for you ?

Paladin76
29 Nov 2010, 5:13 AM
That fix does not work in my case :(


I confirm this bug, and I am amazed nobody has fixed it yet!
I tried this fix, and it seems to work fine:


Ext.grid.ColumnModel.prototype.setState=function(col, state){
state = Ext.applyIf(state, this.defaults);
Ext.apply(this.lookup[col], state);
}

pouniok
2 Dec 2010, 2:08 AM
I was wondering why my columns coulnd't be sorted anymore in Ext 3.3, and came to the conclusion that it was a state restoring problem.

Reproducible with the Array Grid ( http://dev.sencha.com/deploy/dev/examples/grid/array-grid.html ), when you move a column, then some of the columns coulnd't be sorted anymore.

Thanks for the fix, I'll try it !


Edit : worked for me with the first fix


Ext.override(Ext.grid.ColumnModel, {
setState: function(col, state){
Ext.applyIf(this.lookup[col], state);
}
});

pouniok
2 Dec 2010, 2:33 AM
Just to add that the problem seems Fixed in Ext 3.3.1, but if you are saving state in a database, you should have to clear it to make it work.

Zolthar
3 Dec 2010, 7:20 AM
It helps to saving column sizes but sort still not working for me :(

meroy
3 Dec 2010, 11:17 PM
We're not able to reproduce this with 3.3.1. Please post a test case by following this thread. Thanks.

http://www.sencha.com/forum/showthread.php?71015-Posting-to-the-Bug-Forum

dizor
31 Mar 2011, 6:01 AM
Any new solution?



Ext.override(Ext.grid.ColumnModel, {
setState: function(col, state){
Ext.applyIf(this.lookup[col], state);
}
});


This works with 3.2.1 but ... save state for hide/show column doesn't work.

EDIT: I just noticed that problem with restore visibility of column is only on first column when i have this:



{header: "ID", width: 50, align: "center", dataIndex: "invoices_id", hidden: true}


If I don't use "hidden" config on first column like that:



{header: "ID", width: 50, align: "center", dataIndex: "invoices_id"}


fix works!

This problem is only with first column in CM and when we change order of columns.

EDIT 2: This works for me:



Ext.override(Ext.grid.ColumnModel, {
setState : function(col, state) {
Ext.apply(this.config[col], state);
}
});

jwc
13 Dec 2011, 9:30 AM
I'm kinda new and learning EXTJS but I guess thats why it says 'OPEN' in the title, because it has not been fixed in any version yet?

I am using 3.4.0 and cannot for the life of me get my grid to restore state between refreshes.

I have:


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

.
.
.
stateId:'IDgridstate',
stateful:true,
.
.
.

I have id's set in my column model for each column.

That should be all I need right? Am I missing something?

I cannot see that the cookies are being set in Firebug. A cookie is set for SESSION and cookies are set for other sites, so I know they are working.

I also tried the fix in this thread ..


Ext.grid.ColumnModel.prototype.setState=function(col, state){
state = Ext.applyIf(state, this.defaults);
Ext.apply(this.lookup[col], state);


Nothing seems to make any difference!

Any ideas?

Thanks