PDA

View Full Version : Sorting with stateful in Grid ?



Paladin76
29 Nov 2010, 4:49 AM
Hi, i've got a beginner fault and i'm not able to find out. Please help.

I have a GroupingGrid, set all Data and stuff and everything works. Now, i added the "stateful: true" and a "stateId: 'something'" and now, the column-sorting is not working after loading the grid (it does store the fields correct, but i am not able to sort and the field "sort xyz" are disabled).

Please help!

Here's my viewport (i changed the true names in there):

var viewport = new Ext.Viewport(
{
layout:'fit',
items:[
new Ext.grid.GridPanel({
store: store,
columns: [
{header: "1", width: 40, sortable: true, dataIndex: 'f1'},
{header: "2", width: 40, sortable: true, dataIndex: 'f2', xtype: 'datecolumn', format: 'd.m.Y'},
{header: "3", width: 40, sortable: true, dataIndex: 'f3'},
{header: "4", width: 80, sortable: true, dataIndex: 'f4'},
{header: "5", width: 80, sortable: true, dataIndex: 'f5'},
{header: "6", width: 120, sortable: true, dataIndex: 'f6'},
{header: "7", width: 60, sortable: true, dataIndex: 'f7'},
{header: "8", width: 60, sortable: true, dataIndex: 'f8'},
{header: "9", width: 20, sortable: true, dataIndex: 'f9'}
],

view: view,

frame:false,
collapsible: false,
title: 'Meine '+store.getCount()+' Tasks',
iconCls: 'icon-grid',
itemId: 'myItemIdForGrid',
fbar : ['->', {
text:'Gruppierung aufheben',
iconCls: 'icon-clear-group',
handler : function(){
store.clearGrouping();
}
},
{
text: 'Alle öffnen',
iconCls: 'icon-expand-all',
handler : function(){
view.expandAllGroups();
}
},
{
text: 'Alle schließen',
iconCls: 'icon-collapse-all',
handler : function(){
view.collapseAllGroups();
}
}
],
stateful: true,
stateId: 'mylist'
})
]
});

Condor
29 Nov 2010, 4:59 AM
1. You should give your columns ids (otherwise the column state is stored by index instead of id - which can become a problem if you ever modify columns).
2. Ext 3.3.0 has a bug in grid state keeping (see Bugs section for fix).

Paladin76
29 Nov 2010, 5:12 AM
Hi, thanks for the quick reply.
First: I added column ids now
Second: The fix in http://www.sencha.com/forum/showthread.php?110961-OPEN-1355-GridPanel-restore-state-bug does not work, when will a fixed version will be there ?

Zolthar
3 Dec 2010, 7:08 AM
Hi,

I have the same problem and noticed when i gave ids to columns sort works but state is not caching column size.
Did somebody have the same problem?

//Update

odd, when i gave ids to columns and applied fix from link above then state saves column size, but sort is still not working...

Zolthar
3 Dec 2010, 7:42 AM
hah, i've found, seems it's defaults problem:

var xg = Ext.grid;

xg.ColumnModel.prototype.setState=function(col, state){
this.defaults.sortable = true;
state = Ext.applyIf(state, this.defaults);
Ext.apply(this.config[col], state);
}


This works fine for saving columns size, and sort is enabled after load page, it works fine for columns without ids, probably when have colids then must change it to:

var xg = Ext.grid;

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

Condor
3 Dec 2010, 7:50 AM
Have you tried upgrading? This should be solved in Ext 3.3.1.

Zolthar
3 Dec 2010, 8:03 AM
how can I upgrade? i don't see link to download, except purchase and evaluate.

Condor
3 Dec 2010, 8:09 AM
Don't see the "Download Open Source" link?

Zolthar
3 Dec 2010, 8:13 AM
OMG indeed, but i thought it's another version, thanks

Zolthar
3 Dec 2010, 8:27 AM
Sorry, indeed columns size is restored but sort problem left :) as I said, it's defaults problem, default sort is false so without manual change default sort to true it won't work

Paladin76
13 Dec 2010, 3:13 AM
Have you tried upgrading? This should be solved in Ext 3.3.1.
Seems to be solved in 3.3.1 in my case, i will monitor this and "deep-test" it now ;)

Paladin76
5 Jan 2011, 5:50 AM
One more thing: The extJS Grouping Grid does not store, which group is closed and which one is opened. Or is there any option i did not see?