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
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
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
20 Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
\r
23 constructor: function(config){
\r
24 Ext.data.GroupingStore.superclass.constructor.call(this, config);
\r
25 this.applyGroupField();
\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
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
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
48 <div id="method-Ext.data.GroupingStore-clearGrouping"></div>/**
\r
49 * Clears any existing grouping and refreshes the data using the default sort.
\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
57 var lo = this.lastOptions;
\r
58 if(lo && lo.params){
\r
59 delete lo.params.groupBy;
\r
64 this.fireEvent('datachanged', this);
\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
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
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
86 if(this.remoteGroup){
\r
89 var si = this.sortInfo || {};
\r
90 if(si.field != field || si.direction != direction){
\r
93 this.sortData(field, direction);
\r
95 this.fireEvent('datachanged', this);
\r
100 applyGroupField: function(){
\r
101 if(this.remoteGroup){
\r
102 if(!this.baseParams){
\r
103 this.baseParams = {};
\r
105 this.baseParams.groupBy = this.groupField;
\r
106 this.baseParams.groupDir = this.groupDir;
\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
122 applyGrouping : function(alwaysFireChange){
\r
123 if(this.groupField !== false){
\r
124 this.groupBy(this.groupField, true, this.groupDir);
\r
127 if(alwaysFireChange === true){
\r
128 this.fireEvent('datachanged', this);
\r
135 getGroupState : function(){
\r
136 return this.groupOnSort && this.groupField !== false ?
\r
137 (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
\r
140 Ext.reg('groupingstore', Ext.data.GroupingStore);</pre>
\r