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