~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/data/GroupingStore.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 2.2
 
3
 * Copyright(c) 2006-2008, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.data.GroupingStore
 
11
 * @extends Ext.data.Store
 
12
 * A specialized store implementation that provides for grouping records by one of the available fields.
 
13
 * @constructor
 
14
 * Creates a new GroupingStore.
 
15
 * @param {Object} config A config object containing the objects needed for the Store to access data,
 
16
 * and read the data into Records.
 
17
 */
 
18
Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
 
19
    /**
 
20
     * @cfg {String} groupField
 
21
     * The field name by which to sort the store's data (defaults to '').
 
22
     */
 
23
    /**
 
24
     * @cfg {Boolean} remoteGroup
 
25
     * True if the grouping should apply on the server side, false if it is local only (defaults to false).  If the
 
26
     * grouping is local, it can be applied immediately to the data.  If it is remote, then it will simply act as a
 
27
     * helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.
 
28
     */
 
29
    remoteGroup : false,
 
30
    /**
 
31
     * @cfg {Boolean} groupOnSort
 
32
     * True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the
 
33
     * existing sort info (defaults to false).
 
34
     */
 
35
    groupOnSort:false,
 
36
 
 
37
    /**
 
38
     * Clears any existing grouping and refreshes the data using the default sort.
 
39
     */
 
40
    clearGrouping : function(){
 
41
        this.groupField = false;
 
42
        if(this.remoteGroup){
 
43
            if(this.baseParams){
 
44
                delete this.baseParams.groupBy;
 
45
            }
 
46
            this.reload();
 
47
        }else{
 
48
            this.applySort();
 
49
            this.fireEvent('datachanged', this);
 
50
        }
 
51
    },
 
52
 
 
53
    /**
 
54
     * Groups the data by the specified field.
 
55
     * @param {String} field The field name by which to sort the store's data
 
56
     * @param {Boolean} forceRegroup (optional) True to force the group to be refreshed even if the field passed
 
57
     * in is the same as the current grouping field, false to skip grouping on the same field (defaults to false)
 
58
     */
 
59
    groupBy : function(field, forceRegroup){
 
60
        if(this.groupField == field && !forceRegroup){
 
61
            return; // already grouped by this field
 
62
        }
 
63
        this.groupField = field;
 
64
        if(this.remoteGroup){
 
65
            if(!this.baseParams){
 
66
                this.baseParams = {};
 
67
            }
 
68
            this.baseParams['groupBy'] = field;
 
69
        }
 
70
        if(this.groupOnSort){
 
71
            this.sort(field);
 
72
            return;
 
73
        }
 
74
        if(this.remoteGroup){
 
75
            this.reload();
 
76
        }else{
 
77
            var si = this.sortInfo || {};
 
78
            if(si.field != field){
 
79
                this.applySort();
 
80
            }else{
 
81
                this.sortData(field);
 
82
            }
 
83
            this.fireEvent('datachanged', this);
 
84
        }
 
85
    },
 
86
 
 
87
    // private
 
88
    applySort : function(){
 
89
        Ext.data.GroupingStore.superclass.applySort.call(this);
 
90
        if(!this.groupOnSort && !this.remoteGroup){
 
91
            var gs = this.getGroupState();
 
92
            if(gs && gs != this.sortInfo.field){
 
93
                this.sortData(this.groupField);
 
94
            }
 
95
        }
 
96
    },
 
97
 
 
98
    // private
 
99
    applyGrouping : function(alwaysFireChange){
 
100
        if(this.groupField !== false){
 
101
            this.groupBy(this.groupField, true);
 
102
            return true;
 
103
        }else{
 
104
            if(alwaysFireChange === true){
 
105
                this.fireEvent('datachanged', this);
 
106
            }
 
107
            return false;
 
108
        }
 
109
    },
 
110
 
 
111
    // private
 
112
    getGroupState : function(){
 
113
        return this.groupOnSort && this.groupField !== false ?
 
114
               (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
 
115
    }
 
116
});
 
 
b'\\ No newline at end of file'