source: trunk/web/addons/job_monarch/lib/extjs/source/data/GroupingStore.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 3.9 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, 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. This
13 * is usually used in conjunction with an {@link Ext.grid.GroupingView} to proved the data model for
14 * a grouped GridPanel.
15 * @constructor
16 * Creates a new GroupingStore.
17 * @param {Object} config A config object containing the objects needed for the Store to access data,
18 * and read the data into Records.
19 */
20Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
21    /**
22     * @cfg {String} groupField
23     * The field name by which to sort the store's data (defaults to '').
24     */
25    /**
26     * @cfg {Boolean} remoteGroup
27     * True if the grouping should apply on the server side, false if it is local only (defaults to false).  If the
28     * grouping is local, it can be applied immediately to the data.  If it is remote, then it will simply act as a
29     * helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.
30     */
31    remoteGroup : false,
32    /**
33     * @cfg {Boolean} groupOnSort
34     * True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the
35     * existing sort info (defaults to false).
36     */
37    groupOnSort:false,
38
39    /**
40     * Clears any existing grouping and refreshes the data using the default sort.
41     */
42    clearGrouping : function(){
43        this.groupField = false;
44        if(this.remoteGroup){
45            if(this.baseParams){
46                delete this.baseParams.groupBy;
47            }
48            this.reload();
49        }else{
50            this.applySort();
51            this.fireEvent('datachanged', this);
52        }
53    },
54
55    /**
56     * Groups the data by the specified field.
57     * @param {String} field The field name by which to sort the store's data
58     * @param {Boolean} forceRegroup (optional) True to force the group to be refreshed even if the field passed
59     * in is the same as the current grouping field, false to skip grouping on the same field (defaults to false)
60     */
61    groupBy : function(field, forceRegroup){
62        if(this.groupField == field && !forceRegroup){
63            return; // already grouped by this field
64        }
65        this.groupField = field;
66        if(this.remoteGroup){
67            if(!this.baseParams){
68                this.baseParams = {};
69            }
70            this.baseParams['groupBy'] = field;
71        }
72        if(this.groupOnSort){
73            this.sort(field);
74            return;
75        }
76        if(this.remoteGroup){
77            this.reload();
78        }else{
79            var si = this.sortInfo || {};
80            if(si.field != field){
81                this.applySort();
82            }else{
83                this.sortData(field);
84            }
85            this.fireEvent('datachanged', this);
86        }
87    },
88
89    // private
90    applySort : function(){
91        Ext.data.GroupingStore.superclass.applySort.call(this);
92        if(!this.groupOnSort && !this.remoteGroup){
93            var gs = this.getGroupState();
94            if(gs && gs != this.sortInfo.field){
95                this.sortData(this.groupField);
96            }
97        }
98    },
99
100    // private
101    applyGrouping : function(alwaysFireChange){
102        if(this.groupField !== false){
103            this.groupBy(this.groupField, true);
104            return true;
105        }else{
106            if(alwaysFireChange === true){
107                this.fireEvent('datachanged', this);
108            }
109            return false;
110        }
111    },
112
113    // private
114    getGroupState : function(){
115        return this.groupOnSort && this.groupField !== false ?
116               (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
117    }
118});
Note: See TracBrowser for help on using the repository browser.