PDA

View Full Version : [OPEN-1124] Grouping Strore requires sortInfo



vishalg
12 Mar 2009, 10:01 AM
Can someone explain me why sortInfo is required if I want to group by a field.

Using the grouping example bundled with Ext you can produce the relevent error by making the following change to ext/examples/grid/grouping.js



26 var grid = new xg.GridPanel({
27 store: new Ext.data.GroupingStore({
28 reader: reader,
29 data: xg.dummyData,
30 //sortInfo:{field: 'company', direction: "ASC"},
31 groupField:'industry'
32 }),

mjlecomte
12 Mar 2009, 11:34 AM
Seems like an oversight. Try:



Ext.override(Ext.data.GroupingStore,{
// private
applySort : function(){
Ext.data.GroupingStore.superclass.applySort.call(this);
if(!this.groupOnSort && !this.remoteGroup){
var gs = this.getGroupState();
if(gs && this.sortInfo && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
this.sortData(this.groupField, this.groupDir);
}
}
}
})

mjlecomte
12 Mar 2009, 11:36 AM
Actually this may be better huh?



Ext.override(Ext.data.GroupingStore,{
// private
applySort : function(){
Ext.data.GroupingStore.superclass.applySort.call(this);
if(!this.groupOnSort && !this.remoteGroup && this.sortInfo){
var gs = this.getGroupState();
if(gs && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
this.sortData(this.groupField, this.groupDir);
}
}
}
})

vishalg
12 Mar 2009, 12:55 PM
Yes your second method is a smarter way to error check.
I would also make this change to have more error checking. Just in case someone does not know what they doing and are missing those two sub properties.



Ext.override(Ext.data.GroupingStore,{
// private
applySort : function(){
Ext.data.GroupingStore.superclass.applySort.call(this);
if(!this.groupOnSort && !this.remoteGroup && this.sortInfo && this.sortInfo.field && this.sortInfo.direction ){
var gs = this.getGroupState();
if(gs && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
this.sortData(this.groupField, this.groupDir);
}
}
}
})
Pheew good to know I wasn't missing the point by trying to not specify sortInfo

mjlecomte
12 Mar 2009, 1:14 PM
There won't be a problem with the sub-properties, they will just evaluate to undefined. The problem is if you check for foo.bar.mop, when foo.bar is undefined.

vishalg
12 Mar 2009, 1:20 PM
There won't be a problem with the sub-properties, they will just evaluate to undefined. The problem is if you check for foo.bar.mop, when foo.bar is undefined.

Agreed; =D>

Tom23
30 Dec 2009, 5:56 AM
If I'm not mistaken, sortData() should be executed if no sortInfo is set, because this is where grouping is achieved. So, the fix should be:


Ext.override(Ext.data.GroupingStore,{
// private
applySort : function(){
Ext.data.GroupingStore.superclass.applySort.call(this);
if(!this.groupOnSort && !this.remoteGroup){
var gs = this.getGroupState();
if(gs && (!this.sortInfo || gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
this.sortData(this.groupField, this.groupDir);
}
}
}
})


PS: This bug is still present in Ext 3.1.
Should I open a new bug report in the Ext3 thread?

Condor
30 Dec 2009, 6:00 AM
No need. I'll move this thread to the 3.x Bugs section.

mattgoldspink
14 Jul 2010, 6:11 AM
That latest fix from Tom23 still didn't work for me I needed this:



Ext.override(Ext.data.GroupingStore,{
// private
applySort : function(){
Ext.data.GroupingStore.superclass.applySort.call(this);
if(!this.groupOnSort && !this.remoteGroup){
var gs = this.getGroupState();
if(gs && (!this.sortInfo || gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
this.groupDir = this.sortInfo.direction;
this.sortData(this.groupField, this.groupDir);
}
}
}
})
Change was to assign a new direction to the groupDir property which then makes the groups also sort in the correct direction.