PDA

View Full Version : [2.x] groupOnSort vs sortOnGroup



Green
20 Feb 2008, 11:10 AM
The original property is called GroupingStore.groupOnSort, and it does exactly what it sounds like, i.e. group whenever you sort your grid. However, it does not do what the documentation suggests, i.e. sort when you group.

So I made an override to GroupingStore:

Ext.data.MyGroupingStore = Ext.extend(Ext.data.GroupingStore, {
sortOnGroup:true,

groupBy : function(field, forceRegroup){
if(this.groupField == field && !forceRegroup){
return; // already grouped by this field
}
this.groupField = field;
if(this.remoteGroup){
if(!this.baseParams){
this.baseParams = {};
}
this.baseParams['groupBy'] = field;
}
if(this.groupOnSort||this.sortOnGroup){
this.sort(field);
return;
}
alert('Now');
if(this.remoteGroup){
this.reload();
}else{
var si = this.sortInfo || {};
if(si.field != field){
this.applySort();
}else{
this.sortData(field);
}
this.fireEvent('datachanged', this);
}
}
});

Now you have two properties, each doing exactly what they sound like. groupOnSort=True will always group each time you sort. While sortOnGroup will sort() the actual data.

Typical scenario: You have a grid containing paged data from a DB. The grid is capable of 'optionally' grouping, but also sort normally. Without sortOnGroup it is impossible to get the GroupingStore to group locally but do it on pertinent data, i.e. data resorted on the grouping column (as most of the data is not in the store, which contains only the current page's data). Instead what you get is grouped data of your current page which may be sorted according to another column than the grouped column. With sortOnGroup=True, the grid will refresh the data (now sorted server-side according to the grouped column) and thus only contain the new page of data (say 25 records) which is then accordingly grouped.

cblin
19 Nov 2008, 8:38 AM
you saved my day...

watrboy00
19 Nov 2008, 10:09 AM
Might want to take out the
alert('Now');

statement.

RobertT
12 Apr 2011, 1:32 AM
If you group, ungroup then group again by the same column/field, you will notice that the first time the data is sorted in asc order, second time the data is sorted in desc order.
Can you please update the code with the fix for this?