Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / GroupingStore.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.data.GroupingStore"></div>/**\r
10  * @class Ext.data.GroupingStore\r
11  * @extends Ext.data.Store\r
12  * A specialized store implementation that provides for grouping records by one of the available fields. This\r
13  * is usually used in conjunction with an {@link Ext.grid.GroupingView} to proved the data model for\r
14  * a grouped GridPanel.\r
15  * @constructor\r
16  * Creates a new GroupingStore.\r
17  * @param {Object} config A config object containing the objects needed for the Store to access data,\r
18  * and read the data into Records.\r
19  * @xtype groupingstore\r
20  */\r
21 Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {\r
22     \r
23     //inherit docs\r
24     constructor: function(config){\r
25         Ext.data.GroupingStore.superclass.constructor.call(this, config);\r
26         this.applyGroupField();\r
27     },\r
28     \r
29     <div id="cfg-Ext.data.GroupingStore-groupField"></div>/**\r
30      * @cfg {String} groupField\r
31      * The field name by which to sort the store's data (defaults to '').\r
32      */\r
33     <div id="cfg-Ext.data.GroupingStore-remoteGroup"></div>/**\r
34      * @cfg {Boolean} remoteGroup\r
35      * True if the grouping should apply on the server side, false if it is local only (defaults to false).  If the\r
36      * grouping is local, it can be applied immediately to the data.  If it is remote, then it will simply act as a\r
37      * helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.\r
38      */\r
39     remoteGroup : false,\r
40     <div id="cfg-Ext.data.GroupingStore-groupOnSort"></div>/**\r
41      * @cfg {Boolean} groupOnSort\r
42      * True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the\r
43      * existing sort info (defaults to false).\r
44      */\r
45     groupOnSort:false,\r
46 \r
47         groupDir : 'ASC',\r
48         \r
49     <div id="method-Ext.data.GroupingStore-clearGrouping"></div>/**\r
50      * Clears any existing grouping and refreshes the data using the default sort.\r
51      */\r
52     clearGrouping : function(){\r
53         this.groupField = false;\r
54         if(this.remoteGroup){\r
55             if(this.baseParams){\r
56                 delete this.baseParams.groupBy;\r
57             }\r
58             var lo = this.lastOptions;\r
59             if(lo && lo.params){\r
60                 delete lo.params.groupBy;\r
61             }\r
62             this.reload();\r
63         }else{\r
64             this.applySort();\r
65             this.fireEvent('datachanged', this);\r
66         }\r
67     },\r
68 \r
69     <div id="method-Ext.data.GroupingStore-groupBy"></div>/**\r
70      * Groups the data by the specified field.\r
71      * @param {String} field The field name by which to sort the store's data\r
72      * @param {Boolean} forceRegroup (optional) True to force the group to be refreshed even if the field passed\r
73      * in is the same as the current grouping field, false to skip grouping on the same field (defaults to false)\r
74      */\r
75     groupBy : function(field, forceRegroup, direction){\r
76                 direction = direction ? (String(direction).toUpperCase() == 'DESC' ? 'DESC' : 'ASC') : this.groupDir;\r
77         if(this.groupField == field && this.groupDir == direction && !forceRegroup){\r
78             return; // already grouped by this field\r
79         }\r
80         this.groupField = field;\r
81                 this.groupDir = direction;\r
82         this.applyGroupField();\r
83         if(this.groupOnSort){\r
84             this.sort(field, direction);\r
85             return;\r
86         }\r
87         if(this.remoteGroup){\r
88             this.reload();\r
89         }else{\r
90             var si = this.sortInfo || {};\r
91             if(si.field != field || si.direction != direction){\r
92                 this.applySort();\r
93             }else{\r
94                 this.sortData(field, direction);\r
95             }\r
96             this.fireEvent('datachanged', this);\r
97         }\r
98     },\r
99     \r
100     // private\r
101     applyGroupField: function(){\r
102         if(this.remoteGroup){\r
103             if(!this.baseParams){\r
104                 this.baseParams = {};\r
105             }\r
106             this.baseParams.groupBy = this.groupField;\r
107             this.baseParams.groupDir = this.groupDir;\r
108         }\r
109     },\r
110 \r
111     // private\r
112     applySort : function(){\r
113         Ext.data.GroupingStore.superclass.applySort.call(this);\r
114         if(!this.groupOnSort && !this.remoteGroup){\r
115             var gs = this.getGroupState();\r
116             if(gs && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){\r
117                 this.sortData(this.groupField, this.groupDir);\r
118             }\r
119         }\r
120     },\r
121 \r
122     // private\r
123     applyGrouping : function(alwaysFireChange){\r
124         if(this.groupField !== false){\r
125             this.groupBy(this.groupField, true, this.groupDir);\r
126             return true;\r
127         }else{\r
128             if(alwaysFireChange === true){\r
129                 this.fireEvent('datachanged', this);\r
130             }\r
131             return false;\r
132         }\r
133     },\r
134 \r
135     // private\r
136     getGroupState : function(){\r
137         return this.groupOnSort && this.groupField !== false ?\r
138                (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;\r
139     }\r
140 });\r
141 Ext.reg('groupingstore', Ext.data.GroupingStore);</pre>    \r
142 </body>\r
143 </html>