1. #1
    Sencha User
    Join Date
    Apr 2007
    Posts
    49
    Vote Rating
    0
    Green is on a distinguished road

      0  

    Default [2.x] groupOnSort vs sortOnGroup

    [2.x] groupOnSort vs sortOnGroup


    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:
    Code:
    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.
    Production: Ext4/Touch2

    "Real programmers use C: >copy con > myprog.exe"

  2. #2
    Sencha User
    Join Date
    Dec 2007
    Posts
    69
    Vote Rating
    0
    cblin is on a distinguished road

      0  

    Default


    you saved my day...

  3. #3
    Ext JS Premium Member watrboy00's Avatar
    Join Date
    Aug 2007
    Location
    Minneapolis, MN
    Posts
    473
    Vote Rating
    0
    watrboy00 is on a distinguished road

      0  

    Default


    Might want to take out the
    alert('Now');

    statement.
    Eric Berens
    Intranet Systems Manager @ Best Buy
    You should follow me on twitter here.

  4. #4
    Sencha User
    Join Date
    Feb 2008
    Posts
    33
    Vote Rating
    0
    RobertT is on a distinguished road

      0  

    Default


    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?

Thread Participants: 3