3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.data.GroupingStore"></div>/**
\r
15 * @class Ext.data.GroupingStore
\r
16 * @extends Ext.data.Store
\r
17 * A specialized store implementation that provides for grouping records by one of the available fields. This
\r
18 * is usually used in conjunction with an {@link Ext.grid.GroupingView} to proved the data model for
\r
19 * a grouped GridPanel.
\r
21 * Creates a new GroupingStore.
\r
22 * @param {Object} config A config object containing the objects needed for the Store to access data,
\r
23 * and read the data into Records.
\r
24 * @xtype groupingstore
\r
26 Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
\r
29 constructor: function(config){
\r
30 Ext.data.GroupingStore.superclass.constructor.call(this, config);
\r
31 this.applyGroupField();
\r
34 <div id="cfg-Ext.data.GroupingStore-groupField"></div>/**
\r
35 * @cfg {String} groupField
\r
36 * The field name by which to sort the store's data (defaults to '').
\r
38 <div id="cfg-Ext.data.GroupingStore-remoteGroup"></div>/**
\r
39 * @cfg {Boolean} remoteGroup
\r
40 * True if the grouping should apply on the server side, false if it is local only (defaults to false). If the
\r
41 * grouping is local, it can be applied immediately to the data. If it is remote, then it will simply act as a
\r
42 * helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.
\r
44 remoteGroup : false,
\r
45 <div id="cfg-Ext.data.GroupingStore-groupOnSort"></div>/**
\r
46 * @cfg {Boolean} groupOnSort
\r
47 * True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the
\r
48 * existing sort info (defaults to false).
\r
54 <div id="method-Ext.data.GroupingStore-clearGrouping"></div>/**
\r
55 * Clears any existing grouping and refreshes the data using the default sort.
\r
57 clearGrouping : function(){
\r
58 this.groupField = false;
\r
59 if(this.remoteGroup){
\r
60 if(this.baseParams){
\r
61 delete this.baseParams.groupBy;
\r
63 var lo = this.lastOptions;
\r
64 if(lo && lo.params){
\r
65 delete lo.params.groupBy;
\r
70 this.fireEvent('datachanged', this);
\r
74 <div id="method-Ext.data.GroupingStore-groupBy"></div>/**
\r
75 * Groups the data by the specified field.
\r
76 * @param {String} field The field name by which to sort the store's data
\r
77 * @param {Boolean} forceRegroup (optional) True to force the group to be refreshed even if the field passed
\r
78 * in is the same as the current grouping field, false to skip grouping on the same field (defaults to false)
\r
80 groupBy : function(field, forceRegroup, direction){
\r
81 direction = direction ? (String(direction).toUpperCase() == 'DESC' ? 'DESC' : 'ASC') : this.groupDir;
\r
82 if(this.groupField == field && this.groupDir == direction && !forceRegroup){
\r
83 return; // already grouped by this field
\r
85 this.groupField = field;
\r
86 this.groupDir = direction;
\r
87 this.applyGroupField();
\r
88 if(this.groupOnSort){
\r
89 this.sort(field, direction);
\r
92 if(this.remoteGroup){
\r
95 var si = this.sortInfo || {};
\r
96 if(si.field != field || si.direction != direction){
\r
99 this.sortData(field, direction);
\r
101 this.fireEvent('datachanged', this);
\r
106 applyGroupField: function(){
\r
107 if(this.remoteGroup){
\r
108 if(!this.baseParams){
\r
109 this.baseParams = {};
\r
111 this.baseParams.groupBy = this.groupField;
\r
112 this.baseParams.groupDir = this.groupDir;
\r
117 applySort : function(){
\r
118 Ext.data.GroupingStore.superclass.applySort.call(this);
\r
119 if(!this.groupOnSort && !this.remoteGroup){
\r
120 var gs = this.getGroupState();
\r
121 if(gs && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
\r
122 this.sortData(this.groupField, this.groupDir);
\r
128 applyGrouping : function(alwaysFireChange){
\r
129 if(this.groupField !== false){
\r
130 this.groupBy(this.groupField, true, this.groupDir);
\r
133 if(alwaysFireChange === true){
\r
134 this.fireEvent('datachanged', this);
\r
141 getGroupState : function(){
\r
142 return this.groupOnSort && this.groupField !== false ?
\r
143 (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
\r
146 Ext.reg('groupingstore', Ext.data.GroupingStore);</pre>