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
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
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
21 Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
\r
24 constructor: function(config){
\r
25 Ext.data.GroupingStore.superclass.constructor.call(this, config);
\r
26 this.applyGroupField();
\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
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
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
49 <div id="method-Ext.data.GroupingStore-clearGrouping"></div>/**
\r
50 * Clears any existing grouping and refreshes the data using the default sort.
\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
58 var lo = this.lastOptions;
\r
59 if(lo && lo.params){
\r
60 delete lo.params.groupBy;
\r
65 this.fireEvent('datachanged', this);
\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
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
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
87 if(this.remoteGroup){
\r
90 var si = this.sortInfo || {};
\r
91 if(si.field != field || si.direction != direction){
\r
94 this.sortData(field, direction);
\r
96 this.fireEvent('datachanged', this);
\r
101 applyGroupField: function(){
\r
102 if(this.remoteGroup){
\r
103 if(!this.baseParams){
\r
104 this.baseParams = {};
\r
106 this.baseParams.groupBy = this.groupField;
\r
107 this.baseParams.groupDir = this.groupDir;
\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
123 applyGrouping : function(alwaysFireChange){
\r
124 if(this.groupField !== false){
\r
125 this.groupBy(this.groupField, true, this.groupDir);
\r
128 if(alwaysFireChange === true){
\r
129 this.fireEvent('datachanged', this);
\r
136 getGroupState : function(){
\r
137 return this.groupOnSort && this.groupField !== false ?
\r
138 (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
\r
141 Ext.reg('groupingstore', Ext.data.GroupingStore);</pre>
\r