3 * @class Ext.data.Store
4 * @extends Ext.data.AbstractStore
6 * <p>The Store class encapsulates a client side cache of {@link Ext.data.Model Model} objects. Stores load
7 * data via a {@link Ext.data.proxy.Proxy Proxy}, and also provide functions for {@link #sort sorting},
8 * {@link #filter filtering} and querying the {@link Ext.data.Model model} instances contained within it.</p>
10 * <p>Creating a Store is easy - we just tell it the Model and the Proxy to use to load and save its data:</p>
13 // Set up a {@link Ext.data.Model model} to use in our Store
15 extend: 'Ext.data.Model',
17 {name: 'firstName', type: 'string'},
18 {name: 'lastName', type: 'string'},
19 {name: 'age', type: 'int'},
20 {name: 'eyeColor', type: 'string'}
24 var myStore = new Ext.data.Store({
38 * <p>In the example above we configured an AJAX proxy to load data from the url '/users.json'. We told our Proxy
39 * to use a {@link Ext.data.reader.Json JsonReader} to parse the response from the server into Model object -
40 * {@link Ext.data.reader.Json see the docs on JsonReader} for details.</p>
42 * <p><u>Inline data</u></p>
44 * <p>Stores can also load data inline. Internally, Store converts each of the objects we pass in as {@link #data}
45 * into Model instances:</p>
51 {firstName: 'Ed', lastName: 'Spencer'},
52 {firstName: 'Tommy', lastName: 'Maintz'},
53 {firstName: 'Aaron', lastName: 'Conran'},
54 {firstName: 'Jamie', lastName: 'Avins'}
59 * <p>Loading inline data using the method above is great if the data is in the correct format already (e.g. it doesn't need
60 * to be processed by a {@link Ext.data.reader.Reader reader}). If your inline data requires processing to decode the data structure,
61 * use a {@link Ext.data.proxy.Memory MemoryProxy} instead (see the {@link Ext.data.proxy.Memory MemoryProxy} docs for an example).</p>
63 * <p>Additional data can also be loaded locally using {@link #add}.</p>
65 * <p><u>Loading Nested Data</u></p>
67 * <p>Applications often need to load sets of associated data - for example a CRM system might load a User and her Orders.
68 * Instead of issuing an AJAX request for the User and a series of additional AJAX requests for each Order, we can load a nested dataset
69 * and allow the Reader to automatically populate the associated models. Below is a brief example, see the {@link Ext.data.reader.Reader} intro
70 * docs for a full explanation:</p>
73 var store = new Ext.data.Store({
87 * <p>Which would consume a response like this:</p>
112 * <p>See the {@link Ext.data.reader.Reader} intro docs for a full explanation.</p>
114 * <p><u>Filtering and Sorting</u></p>
116 * <p>Stores can be sorted and filtered - in both cases either remotely or locally. The {@link #sorters} and {@link #filters} are
117 * held inside {@link Ext.util.MixedCollection MixedCollection} instances to make them easy to manage. Usually it is sufficient to
118 * either just specify sorters and filters in the Store configuration or call {@link #sort} or {@link #filter}:
121 var store = new Ext.data.Store({
129 property : 'firstName',
136 property: 'firstName',
143 * <p>The new Store will keep the configured sorters and filters in the MixedCollection instances mentioned above. By default, sorting
144 * and filtering are both performed locally by the Store - see {@link #remoteSort} and {@link #remoteFilter} to allow the server to
145 * perform these operations instead.</p>
147 * <p>Filtering and sorting after the Store has been instantiated is also easy. Calling {@link #filter} adds another filter to the Store
148 * and automatically filters the dataset (calling {@link #filter} with no arguments simply re-applies all existing filters). Note that by
149 * default {@link #sortOnFilter} is set to true, which means that your sorters are automatically reapplied if using local sorting.</p>
152 store.filter('eyeColor', 'Brown');
155 * <p>Change the sorting at any time by calling {@link #sort}:</p>
158 store.sort('height', 'ASC');
161 * <p>Note that all existing sorters will be removed in favor of the new sorter data (if {@link #sort} is called with no arguments,
162 * the existing sorters are just reapplied instead of being removed). To keep existing sorters and add new ones, just add them
163 * to the MixedCollection:</p>
166 store.sorters.add(new Ext.util.Sorter({
167 property : 'shoeSize',
174 * <p><u>Registering with StoreManager</u></p>
176 * <p>Any Store that is instantiated with a {@link #storeId} will automatically be registed with the {@link Ext.data.StoreManager StoreManager}.
177 * This makes it easy to reuse the same store in multiple views:</p>
180 //this store can be used several times
183 storeId: 'usersStore'
189 //other config goes here
195 //other config goes here
199 * <p><u>Further Reading</u></p>
201 * <p>Stores are backed up by an ecosystem of classes that enables their operation. To gain a full understanding of these
202 * pieces and how they fit together, see:</p>
204 * <ul style="list-style-type: disc; padding-left: 25px">
205 * <li>{@link Ext.data.proxy.Proxy Proxy} - overview of what Proxies are and how they are used</li>
206 * <li>{@link Ext.data.Model Model} - the core class in the data package</li>
207 * <li>{@link Ext.data.reader.Reader Reader} - used by any subclass of {@link Ext.data.proxy.Server ServerProxy} to read a response</li>
211 * @param {Object} config Optional config object
213 Ext.define('Ext.data.Store', {
214 extend: 'Ext.data.AbstractStore',
216 alias: 'store.store',
218 requires: ['Ext.ModelManager', 'Ext.data.Model', 'Ext.util.Grouper'],
219 uses: ['Ext.data.proxy.Memory'],
222 * @cfg {Boolean} remoteSort
223 * True to defer any sorting operation to the server. If false, sorting is done locally on the client. Defaults to <tt>false</tt>.
228 * @cfg {Boolean} remoteFilter
229 * True to defer any filtering operation to the server. If false, filtering is done locally on the client. Defaults to <tt>false</tt>.
234 * @cfg {Boolean} remoteGroup
235 * True if the grouping should apply on the server side, false if it is local only (defaults to false). If the
236 * grouping is local, it can be applied immediately to the data. If it is remote, then it will simply act as a
237 * helper, automatically sending the grouping information to the server.
242 * @cfg {String/Ext.data.proxy.Proxy/Object} proxy The Proxy to use for this Store. This can be either a string, a config
243 * object or a Proxy instance - see {@link #setProxy} for details.
247 * @cfg {Array} data Optional array of Model instances or data objects to load locally. See "Inline data" above for details.
251 * @cfg {String} model The {@link Ext.data.Model} associated with this store
255 * The (optional) field by which to group data in the store. Internally, grouping is very similar to sorting - the
256 * groupField and {@link #groupDir} are injected as the first sorter (see {@link #sort}). Stores support a single
257 * level of grouping, and groups can be fetched via the {@link #getGroups} method.
258 * @property groupField
261 groupField: undefined,
264 * The direction in which sorting should be applied when grouping. Defaults to "ASC" - the other supported value is "DESC"
271 * @cfg {Number} pageSize
272 * The number of records considered to form a 'page'. This is used to power the built-in
273 * paging using the nextPage and previousPage functions. Defaults to 25.
278 * The page that the Store has most recently loaded (see {@link #loadPage})
279 * @property currentPage
285 * @cfg {Boolean} clearOnPageLoad True to empty the store when loading another page via {@link #loadPage},
286 * {@link #nextPage} or {@link #previousPage} (defaults to true). Setting to false keeps existing records, allowing
287 * large data sets to be loaded one page at a time but rendered all together.
289 clearOnPageLoad: true,
292 * True if the Store is currently loading via its Proxy
300 * @cfg {Boolean} sortOnFilter For local filtering only, causes {@link #sort} to be called whenever {@link #filter} is called,
301 * causing the sorters to be reapplied after filtering. Defaults to true
306 * @cfg {Boolean} buffered
307 * Allow the store to buffer and pre-fetch pages of records. This is to be used in conjunction with a view will
308 * tell the store to pre-fetch records ahead of a time.
313 * @cfg {Number} purgePageCount
314 * The number of pages to keep in the cache before purging additional records. A value of 0 indicates to never purge the prefetched data.
315 * This option is only relevant when the {@link #buffered} option is set to true.
322 constructor: function(config) {
323 config = config || {};
326 groupers = config.groupers || me.groupers,
327 groupField = config.groupField || me.groupField,
331 if (config.buffered || me.buffered) {
332 me.prefetchData = Ext.create('Ext.util.MixedCollection', false, function(record) {
335 me.pendingRequests = [];
336 me.pagesRequested = [];
338 me.sortOnLoad = false;
339 me.filterOnLoad = false;
344 * @event beforeprefetch
345 * Fires before a prefetch occurs. Return false to cancel.
346 * @param {Ext.data.store} this
347 * @param {Ext.data.Operation} operation The associated operation
352 * Fired whenever the grouping in the grid changes
353 * @param {Ext.data.Store} store The store
354 * @param {Array} groupers The array of grouper objects
359 * Fires whenever records have been prefetched
360 * @param {Ext.data.store} this
361 * @param {Array} records An array of records
362 * @param {Boolean} successful True if the operation was successful.
363 * @param {Ext.data.Operation} operation The associated operation
367 data = config.data || me.data;
370 * The MixedCollection that holds this store's local cache of records
372 * @type Ext.util.MixedCollection
374 me.data = Ext.create('Ext.util.MixedCollection', false, function(record) {
375 return record.internalId;
379 me.inlineData = data;
383 if (!groupers && groupField) {
385 property : groupField,
386 direction: config.groupDir || me.groupDir
389 delete config.groupers;
392 * The collection of {@link Ext.util.Grouper Groupers} currently applied to this Store
394 * @type Ext.util.MixedCollection
396 me.groupers = Ext.create('Ext.util.MixedCollection');
397 me.groupers.addAll(me.decodeGroupers(groupers));
399 this.callParent([config]);
400 // don't use *config* anymore from here on... use *me* instead...
402 if (me.groupers.items.length) {
403 me.sort(me.groupers.items, 'prepend', false);
407 data = me.inlineData;
410 if (proxy instanceof Ext.data.proxy.Memory) {
414 me.add.apply(me, data);
418 delete me.inlineData;
419 } else if (me.autoLoad) {
420 Ext.defer(me.load, 10, me, [typeof me.autoLoad === 'object' ? me.autoLoad: undefined]);
421 // Remove the defer call, we may need reinstate this at some point, but currently it's not obvious why it's here.
422 // this.load(typeof this.autoLoad == 'object' ? this.autoLoad : undefined);
426 onBeforeSort: function() {
427 this.sort(this.groupers.items, 'prepend', false);
432 * Normalizes an array of grouper objects, ensuring that they are all Ext.util.Grouper instances
433 * @param {Array} groupers The groupers array
434 * @return {Array} Array of Ext.util.Grouper objects
436 decodeGroupers: function(groupers) {
437 if (!Ext.isArray(groupers)) {
438 if (groupers === undefined) {
441 groupers = [groupers];
445 var length = groupers.length,
446 Grouper = Ext.util.Grouper,
449 for (i = 0; i < length; i++) {
450 config = groupers[i];
452 if (!(config instanceof Grouper)) {
453 if (Ext.isString(config)) {
459 Ext.applyIf(config, {
464 //support for 3.x style sorters where a function can be defined as 'fn'
466 config.sorterFn = config.fn;
469 //support a function to be passed as a sorter definition
470 if (typeof config == 'function') {
476 groupers[i] = new Grouper(config);
484 * Group data in the store
485 * @param {String|Array} groupers Either a string name of one of the fields in this Store's configured {@link Ext.data.Model Model},
486 * or an Array of grouper configurations.
487 * @param {String} direction The overall direction to group the data by. Defaults to "ASC".
489 group: function(groupers, direction) {
494 if (Ext.isArray(groupers)) {
495 newGroupers = groupers;
496 } else if (Ext.isObject(groupers)) {
497 newGroupers = [groupers];
498 } else if (Ext.isString(groupers)) {
499 grouper = me.groupers.get(groupers);
506 newGroupers = [grouper];
507 } else if (direction === undefined) {
510 grouper.setDirection(direction);
514 if (newGroupers && newGroupers.length) {
515 newGroupers = me.decodeGroupers(newGroupers);
517 me.groupers.addAll(newGroupers);
520 if (me.remoteGroup) {
523 callback: me.fireGroupChange
527 me.fireEvent('groupchange', me, me.groupers);
532 * Clear any groupers in the store
534 clearGrouping: function(){
536 // Clear any groupers we pushed on to the sorters
537 me.groupers.each(function(grouper){
538 me.sorters.remove(grouper);
541 if (me.remoteGroup) {
544 callback: me.fireGroupChange
548 me.fireEvent('groupchange', me, me.groupers);
553 * Checks if the store is currently grouped
554 * @return {Boolean} True if the store is grouped.
556 isGrouped: function() {
557 return this.groupers.getCount() > 0;
561 * Fires the groupchange event. Abstracted out so we can use it
565 fireGroupChange: function(){
566 this.fireEvent('groupchange', this, this.groupers);
570 * Returns an object containing the result of applying grouping to the records in this store. See {@link #groupField},
571 * {@link #groupDir} and {@link #getGroupString}. Example for a store containing records with a color field:
573 var myStore = new Ext.data.Store({
578 myStore.getGroups(); //returns:
583 //all records where the color field is 'yellow'
589 //all records where the color field is 'red'
594 * @param {String} groupName (Optional) Pass in an optional groupName argument to access a specific group as defined by {@link #getGroupString}
595 * @return {Array} The grouped data
597 getGroups: function(requestGroupString) {
598 var records = this.data.items,
599 length = records.length,
607 for (i = 0; i < length; i++) {
609 groupStr = this.getGroupString(record);
610 group = pointers[groupStr];
612 if (group === undefined) {
619 pointers[groupStr] = group;
622 group.children.push(record);
625 return requestGroupString ? pointers[requestGroupString] : groups;
630 * For a given set of records and a Grouper, returns an array of arrays - each of which is the set of records
631 * matching a certain group.
633 getGroupsForGrouper: function(records, grouper) {
634 var length = records.length,
642 for (i = 0; i < length; i++) {
644 newValue = grouper.getGroupString(record);
646 if (newValue !== oldValue) {
655 group.records.push(record);
665 * This is used recursively to gather the records into the configured Groupers. The data MUST have been sorted for
666 * this to work properly (see {@link #getGroupData} and {@link #getGroupsForGrouper}) Most of the work is done by
667 * {@link #getGroupsForGrouper} - this function largely just handles the recursion.
668 * @param {Array} records The set or subset of records to group
669 * @param {Number} grouperIndex The grouper index to retrieve
670 * @return {Array} The grouped records
672 getGroupsForGrouperIndex: function(records, grouperIndex) {
674 groupers = me.groupers,
675 grouper = groupers.getAt(grouperIndex),
676 groups = me.getGroupsForGrouper(records, grouper),
677 length = groups.length,
680 if (grouperIndex + 1 < groupers.length) {
681 for (i = 0; i < length; i++) {
682 groups[i].children = me.getGroupsForGrouperIndex(groups[i].records, grouperIndex + 1);
686 for (i = 0; i < length; i++) {
687 groups[i].depth = grouperIndex;
695 * <p>Returns records grouped by the configured {@link #groupers grouper} configuration. Sample return value (in
696 * this case grouping by genre and then author in a fictional books dataset):</p>
703 //book1, book2, book3, book4
724 * @param {Boolean} sort True to call {@link #sort} before finding groups. Sorting is required to make grouping
725 * function correctly so this should only be set to false if the Store is known to already be sorted correctly
727 * @return {Array} The group data
729 getGroupData: function(sort) {
731 if (sort !== false) {
735 return me.getGroupsForGrouperIndex(me.data.items, 0);
739 * <p>Returns the string to group on for a given model instance. The default implementation of this method returns
740 * the model's {@link #groupField}, but this can be overridden to group by an arbitrary string. For example, to
741 * group by the first letter of a model's 'name' field, use the following code:</p>
745 getGroupString: function(instance) {
746 return instance.get('name')[0];
750 * @param {Ext.data.Model} instance The model instance
751 * @return {String} The string to compare when forming groups
753 getGroupString: function(instance) {
754 var group = this.groupers.first();
756 return instance.get(group.property);
761 * Inserts Model instances into the Store at the given index and fires the {@link #add} event.
762 * See also <code>{@link #add}</code>.
763 * @param {Number} index The start index at which to insert the passed Records.
764 * @param {Ext.data.Model[]} records An Array of Ext.data.Model objects to add to the cache.
766 insert: function(index, records) {
773 records = [].concat(records);
774 for (i = 0, len = records.length; i < len; i++) {
775 record = me.createModel(records[i]);
776 record.set(me.modelDefaults);
777 // reassign the model in the array in case it wasn't created yet
780 me.data.insert(index + i, record);
783 sync = sync || record.phantom === true;
787 me.snapshot.addAll(records);
790 me.fireEvent('add', me, records, index);
791 me.fireEvent('datachanged', me);
792 if (me.autoSync && sync) {
798 * Adds Model instances to the Store by instantiating them based on a JavaScript object. When adding already-
799 * instantiated Models, use {@link #insert} instead. The instances will be added at the end of the existing collection.
800 * This method accepts either a single argument array of Model instances or any number of model instance arguments.
804 myStore.add({some: 'data'}, {some: 'other data'});
807 * @param {Object} data The data for each model
808 * @return {Array} The array of newly created model instances
810 add: function(records) {
811 //accept both a single-argument array of records, or any number of record arguments
812 if (!Ext.isArray(records)) {
813 records = Array.prototype.slice.apply(arguments);
818 length = records.length,
821 for (; i < length; i++) {
822 record = me.createModel(records[i]);
823 // reassign the model in the array in case it wasn't created yet
827 me.insert(me.data.length, records);
833 * Converts a literal to a model, if it's not a model already
835 * @param record {Ext.data.Model/Object} The record to create
836 * @return {Ext.data.Model}
838 createModel: function(record) {
839 if (!record.isModel) {
840 record = Ext.ModelManager.create(record, this.model);
847 * Calls the specified function for each of the {@link Ext.data.Model Records} in the cache.
848 * @param {Function} fn The function to call. The {@link Ext.data.Model Record} is passed as the first parameter.
849 * Returning <tt>false</tt> aborts and exits the iteration.
850 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed.
851 * Defaults to the current {@link Ext.data.Model Record} in the iteration.
853 each: function(fn, scope) {
854 this.data.each(fn, scope);
858 * Removes the given record from the Store, firing the 'remove' event for each instance that is removed, plus a single
859 * 'datachanged' event after removal.
860 * @param {Ext.data.Model/Array} records The Ext.data.Model instance or array of instances to remove
862 remove: function(records, /* private */ isMove) {
863 if (!Ext.isArray(records)) {
868 * Pass the isMove parameter if we know we're going to be re-inserting this record
870 isMove = isMove === true;
874 length = records.length,
879 for (; i < length; i++) {
881 index = me.data.indexOf(record);
884 me.snapshot.remove(record);
888 isPhantom = record.phantom === true;
889 if (!isMove && !isPhantom) {
890 // don't push phantom records onto removed
891 me.removed.push(record);
895 me.data.remove(record);
896 sync = sync || !isPhantom;
898 me.fireEvent('remove', me, record, index);
902 me.fireEvent('datachanged', me);
903 if (!isMove && me.autoSync && sync) {
909 * Removes the model instance at the given index
910 * @param {Number} index The record index
912 removeAt: function(index) {
913 var record = this.getAt(index);
921 * <p>Loads data into the Store via the configured {@link #proxy}. This uses the Proxy to make an
922 * asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved
923 * instances into the Store and calling an optional callback if required. Example usage:</p>
928 callback: function(records, operation, success) {
929 //the {@link Ext.data.Operation operation} object contains all of the details of the load operation
930 console.log(records);
935 * <p>If the callback scope does not need to be set, a function can simply be passed:</p>
938 store.load(function(records, operation, success) {
939 console.log('loaded records');
943 * @param {Object/Function} options Optional config object, passed into the Ext.data.Operation object before loading.
945 load: function(options) {
948 options = options || {};
950 if (Ext.isFunction(options)) {
956 Ext.applyIf(options, {
957 groupers: me.groupers.items,
958 page: me.currentPage,
959 start: (me.currentPage - 1) * me.pageSize,
964 return me.callParent([options]);
969 * Called internally when a Proxy has completed a load request
971 onProxyLoad: function(operation) {
973 resultSet = operation.getResultSet(),
974 records = operation.getRecords(),
975 successful = operation.wasSuccessful();
978 me.totalCount = resultSet.total;
982 me.loadRecords(records, operation);
986 me.fireEvent('load', me, records, successful);
988 //TODO: deprecate this event, it should always have been 'load' instead. 'load' is now documented, 'read' is not.
989 //People are definitely using this so can't deprecate safely until 2.x
990 me.fireEvent('read', me, records, operation.wasSuccessful());
992 //this is a callback that would have been passed to the 'read' function and is optional
993 Ext.callback(operation.callback, operation.scope || me, [records, operation, successful]);
997 * Create any new records when a write is returned from the server.
999 * @param {Array} records The array of new records
1000 * @param {Ext.data.Operation} operation The operation that just completed
1001 * @param {Boolean} success True if the operation was successful
1003 onCreateRecords: function(records, operation, success) {
1007 snapshot = this.snapshot,
1008 length = records.length,
1009 originalRecords = operation.records,
1015 * Loop over each record returned from the server. Assume they are
1016 * returned in order of how they were sent. If we find a matching
1017 * record, replace it with the newly created one.
1019 for (; i < length; ++i) {
1020 record = records[i];
1021 original = originalRecords[i];
1023 index = data.indexOf(original);
1025 data.removeAt(index);
1026 data.insert(index, record);
1029 index = snapshot.indexOf(original);
1031 snapshot.removeAt(index);
1032 snapshot.insert(index, record);
1035 record.phantom = false;
1043 * Update any records when a write is returned from the server.
1045 * @param {Array} records The array of updated records
1046 * @param {Ext.data.Operation} operation The operation that just completed
1047 * @param {Boolean} success True if the operation was successful
1049 onUpdateRecords: function(records, operation, success){
1052 length = records.length,
1054 snapshot = this.snapshot,
1057 for (; i < length; ++i) {
1058 record = records[i];
1059 data.replace(record);
1061 snapshot.replace(record);
1069 * Remove any records when a write is returned from the server.
1071 * @param {Array} records The array of removed records
1072 * @param {Ext.data.Operation} operation The operation that just completed
1073 * @param {Boolean} success True if the operation was successful
1075 onDestroyRecords: function(records, operation, success){
1079 length = records.length,
1081 snapshot = me.snapshot,
1084 for (; i < length; ++i) {
1085 record = records[i];
1087 data.remove(record);
1089 snapshot.remove(record);
1097 getNewRecords: function() {
1098 return this.data.filterBy(this.filterNew).items;
1102 getUpdatedRecords: function() {
1103 return this.data.filterBy(this.filterUpdated).items;
1107 * Filters the loaded set of records by a given set of filters.
1108 * @param {Mixed} filters The set of filters to apply to the data. These are stored internally on the store,
1109 * but the filtering itself is done on the Store's {@link Ext.util.MixedCollection MixedCollection}. See
1110 * MixedCollection's {@link Ext.util.MixedCollection#filter filter} method for filter syntax. Alternatively,
1111 * pass in a property string
1112 * @param {String} value Optional value to filter by (only if using a property string as the first argument)
1114 filter: function(filters, value) {
1115 if (Ext.isString(filters)) {
1123 decoded = me.decodeFilters(filters),
1125 doLocalSort = me.sortOnFilter && !me.remoteSort,
1126 length = decoded.length;
1128 for (; i < length; i++) {
1129 me.filters.replace(decoded[i]);
1132 if (me.remoteFilter) {
1133 //the load function will pick up the new filters and request the filtered data from the proxy
1137 * A pristine (unfiltered) collection of the records in this store. This is used to reinstate
1138 * records when a filter is removed or changed
1139 * @property snapshot
1140 * @type Ext.util.MixedCollection
1142 if (me.filters.getCount()) {
1143 me.snapshot = me.snapshot || me.data.clone();
1144 me.data = me.data.filter(me.filters.items);
1149 // fire datachanged event if it hasn't already been fired by doSort
1150 if (!doLocalSort || me.sorters.length < 1) {
1151 me.fireEvent('datachanged', me);
1158 * Revert to a view of the Record cache with no filtering applied.
1159 * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
1160 * {@link #datachanged} event.
1162 clearFilter: function(suppressEvent) {
1167 if (me.remoteFilter) {
1169 } else if (me.isFiltered()) {
1170 me.data = me.snapshot.clone();
1173 if (suppressEvent !== true) {
1174 me.fireEvent('datachanged', me);
1180 * Returns true if this store is currently filtered
1183 isFiltered: function() {
1184 var snapshot = this.snapshot;
1185 return !! snapshot && snapshot !== this.data;
1189 * Filter by a function. The specified function will be called for each
1190 * Record in this Store. If the function returns <tt>true</tt> the Record is included,
1191 * otherwise it is filtered out.
1192 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1193 * <li><b>record</b> : Ext.data.Model<p class="sub-desc">The {@link Ext.data.Model record}
1194 * to test for filtering. Access field values using {@link Ext.data.Model#get}.</p></li>
1195 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1197 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1199 filterBy: function(fn, scope) {
1202 me.snapshot = me.snapshot || me.data.clone();
1203 me.data = me.queryBy(fn, scope || me);
1204 me.fireEvent('datachanged', me);
1208 * Query the cached records in this Store using a filtering function. The specified function
1209 * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
1210 * included in the results.
1211 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1212 * <li><b>record</b> : Ext.data.Model<p class="sub-desc">The {@link Ext.data.Model record}
1213 * to test for filtering. Access field values using {@link Ext.data.Model#get}.</p></li>
1214 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1216 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1217 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1219 queryBy: function(fn, scope) {
1221 data = me.snapshot || me.data;
1222 return data.filterBy(fn, scope || me);
1226 * Loads an array of data straight into the Store
1227 * @param {Array} data Array of data to load. Any non-model instances will be cast into model instances first
1228 * @param {Boolean} append True to add the records to the existing records in the store, false to remove the old ones first
1230 loadData: function(data, append) {
1231 var model = this.model,
1232 length = data.length,
1236 //make sure each data element is an Ext.data.Model instance
1237 for (i = 0; i < length; i++) {
1240 if (! (record instanceof Ext.data.Model)) {
1241 data[i] = Ext.ModelManager.create(record, model);
1245 this.loadRecords(data, {addRecords: append});
1249 * Loads an array of {@Ext.data.Model model} instances into the store, fires the datachanged event. This should only usually
1250 * be called internally when loading from the {@link Ext.data.proxy.Proxy Proxy}, when adding records manually use {@link #add} instead
1251 * @param {Array} records The array of records to load
1252 * @param {Object} options {addRecords: true} to add these records to the existing records, false to remove the Store's existing records first
1254 loadRecords: function(records, options) {
1257 length = records.length;
1259 options = options || {};
1262 if (!options.addRecords) {
1267 me.data.addAll(records);
1269 //FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.
1270 for (; i < length; i++) {
1271 if (options.start !== undefined) {
1272 records[i].index = options.start + i;
1275 records[i].join(me);
1279 * this rather inelegant suspension and resumption of events is required because both the filter and sort functions
1280 * fire an additional datachanged event, which is not wanted. Ideally we would do this a different way. The first
1281 * datachanged event is fired by the call to this.add, above.
1285 if (me.filterOnLoad && !me.remoteFilter) {
1289 if (me.sortOnLoad && !me.remoteSort) {
1294 me.fireEvent('datachanged', me, records);
1299 * Loads a given 'page' of data by setting the start and limit values appropriately. Internally this just causes a normal
1300 * load operation, passing in calculated 'start' and 'limit' params
1301 * @param {Number} page The number of the page to load
1303 loadPage: function(page) {
1306 me.currentPage = page;
1310 start: (page - 1) * me.pageSize,
1312 addRecords: !me.clearOnPageLoad
1317 * Loads the next 'page' in the current data set
1319 nextPage: function() {
1320 this.loadPage(this.currentPage + 1);
1324 * Loads the previous 'page' in the current data set
1326 previousPage: function() {
1327 this.loadPage(this.currentPage - 1);
1331 clearData: function() {
1332 this.data.each(function(record) {
1341 * Prefetches data the Store using its configured {@link #proxy}.
1342 * @param {Object} options Optional config object, passed into the Ext.data.Operation object before loading.
1345 prefetch: function(options) {
1348 requestId = me.getRequestId();
1350 options = options || {};
1352 Ext.applyIf(options, {
1354 filters: me.filters.items,
1355 sorters: me.sorters.items,
1356 requestId: requestId
1358 me.pendingRequests.push(requestId);
1360 operation = Ext.create('Ext.data.Operation', options);
1362 // HACK to implement loadMask support.
1363 //if (operation.blocking) {
1364 // me.fireEvent('beforeload', me, operation);
1366 if (me.fireEvent('beforeprefetch', me, operation) !== false) {
1368 me.proxy.read(operation, me.onProxyPrefetch, me);
1375 * Prefetches a page of data.
1376 * @param {Number} page The page to prefetch
1377 * @param {Object} options Optional config object, passed into the Ext.data.Operation object before loading.
1381 prefetchPage: function(page, options) {
1383 pageSize = me.pageSize,
1384 start = (page - 1) * me.pageSize,
1385 end = start + pageSize;
1387 // Currently not requesting this page and range isn't already satisified
1388 if (Ext.Array.indexOf(me.pagesRequested, page) === -1 && !me.rangeSatisfied(start, end)) {
1389 options = options || {};
1390 me.pagesRequested.push(page);
1391 Ext.applyIf(options, {
1395 callback: me.onWaitForGuarantee,
1399 me.prefetch(options);
1405 * Returns a unique requestId to track requests.
1408 getRequestId: function() {
1409 this.requestSeed = this.requestSeed || 1;
1410 return this.requestSeed++;
1414 * Handles a success pre-fetch
1416 * @param {Ext.data.Operation} operation The operation that completed
1418 onProxyPrefetch: function(operation) {
1420 resultSet = operation.getResultSet(),
1421 records = operation.getRecords(),
1423 successful = operation.wasSuccessful();
1426 me.totalCount = resultSet.total;
1427 me.fireEvent('totalcountchange', me.totalCount);
1431 me.cacheRecords(records, operation);
1433 Ext.Array.remove(me.pendingRequests, operation.requestId);
1434 if (operation.page) {
1435 Ext.Array.remove(me.pagesRequested, operation.page);
1439 me.fireEvent('prefetch', me, records, successful, operation);
1441 // HACK to support loadMask
1442 if (operation.blocking) {
1443 me.fireEvent('load', me, records, successful);
1446 //this is a callback that would have been passed to the 'read' function and is optional
1447 Ext.callback(operation.callback, operation.scope || me, [records, operation, successful]);
1451 * Caches the records in the prefetch and stripes them with their server-side
1454 * @param {Array} records The records to cache
1455 * @param {Ext.data.Operation} The associated operation
1457 cacheRecords: function(records, operation) {
1460 length = records.length,
1461 start = operation ? operation.start : 0;
1463 if (!Ext.isDefined(me.totalCount)) {
1464 me.totalCount = records.length;
1465 me.fireEvent('totalcountchange', me.totalCount);
1468 for (; i < length; i++) {
1469 // this is the true index, not the viewIndex
1470 records[i].index = start + i;
1473 me.prefetchData.addAll(records);
1474 if (me.purgePageCount) {
1482 * Purge the least recently used records in the prefetch if the purgeCount
1483 * has been exceeded.
1485 purgeRecords: function() {
1487 prefetchCount = me.prefetchData.getCount(),
1488 purgeCount = me.purgePageCount * me.pageSize,
1489 numRecordsToPurge = prefetchCount - purgeCount - 1,
1492 for (; i <= numRecordsToPurge; i++) {
1493 me.prefetchData.removeAt(0);
1498 * Determines if the range has already been satisfied in the prefetchData.
1500 * @param {Number} start The start index
1501 * @param {Number} end The end index in the range
1503 rangeSatisfied: function(start, end) {
1508 for (; i < end; i++) {
1509 if (!me.prefetchData.getByKey(i)) {
1512 if (end - i > me.pageSize) {
1513 Ext.Error.raise("A single page prefetch could never satisfy this request.");
1523 * Determines the page from a record index
1524 * @param {Number} index The record index
1525 * @return {Number} The page the record belongs to
1527 getPageFromRecordIndex: function(index) {
1528 return Math.floor(index / this.pageSize) + 1;
1532 * Handles a guaranteed range being loaded
1535 onGuaranteedRange: function() {
1537 totalCount = me.getTotalCount(),
1538 start = me.requestStart,
1539 end = ((totalCount - 1) < me.requestEnd) ? totalCount - 1 : me.requestEnd,
1546 Ext.Error.raise("Start (" + start + ") was greater than end (" + end + ")");
1550 if (start !== me.guaranteedStart && end !== me.guaranteedEnd) {
1551 me.guaranteedStart = start;
1552 me.guaranteedEnd = end;
1554 for (; i <= end; i++) {
1555 record = me.prefetchData.getByKey(i);
1558 Ext.Error.raise("Record was not found and store said it was guaranteed");
1563 me.fireEvent('guaranteedrange', range, start, end);
1565 me.cb.call(me.scope || me, range);
1572 // hack to support loadmask
1575 this.fireEvent('beforeload');
1578 // hack to support loadmask
1579 unmask: function() {
1581 this.fireEvent('load');
1586 * Returns the number of pending requests out.
1588 hasPendingRequests: function() {
1589 return this.pendingRequests.length;
1593 // wait until all requests finish, until guaranteeing the range.
1594 onWaitForGuarantee: function() {
1595 if (!this.hasPendingRequests()) {
1596 this.onGuaranteedRange();
1601 * Guarantee a specific range, this will load the store with a range (that
1602 * must be the pageSize or smaller) and take care of any loading that may
1605 guaranteeRange: function(start, end, cb, scope) {
1608 if (end - start > this.pageSize) {
1612 pageSize: this.pageSize,
1613 msg: "Requested a bigger range than the specified pageSize"
1619 end = (end > this.totalCount) ? this.totalCount - 1 : end;
1623 prefetchData = me.prefetchData,
1625 startLoaded = !!prefetchData.getByKey(start),
1626 endLoaded = !!prefetchData.getByKey(end),
1627 startPage = me.getPageFromRecordIndex(start),
1628 endPage = me.getPageFromRecordIndex(end);
1633 me.requestStart = start;
1634 me.requestEnd = end;
1635 // neither beginning or end are loaded
1636 if (!startLoaded || !endLoaded) {
1637 // same page, lets load it
1638 if (startPage === endPage) {
1640 me.prefetchPage(startPage, {
1642 callback: me.onWaitForGuarantee,
1645 // need to load two pages
1648 me.prefetchPage(startPage, {
1650 callback: me.onWaitForGuarantee,
1653 me.prefetchPage(endPage, {
1655 callback: me.onWaitForGuarantee,
1659 // Request was already satisfied via the prefetch
1661 me.onGuaranteedRange();
1665 // because prefetchData is stored by index
1666 // this invalidates all of the prefetchedData
1669 prefetchData = me.prefetchData,
1676 if (me.remoteSort) {
1677 prefetchData.clear();
1678 me.callParent(arguments);
1680 sorters = me.getSorters();
1681 start = me.guaranteedStart;
1682 end = me.guaranteedEnd;
1684 if (sorters.length) {
1685 prefetchData.sort(sorters);
1686 range = prefetchData.getRange();
1687 prefetchData.clear();
1688 me.cacheRecords(range);
1689 delete me.guaranteedStart;
1690 delete me.guaranteedEnd;
1691 me.guaranteeRange(start, end);
1693 me.callParent(arguments);
1696 me.callParent(arguments);
1700 // overriden to provide striping of the indexes as sorting occurs.
1701 // this cannot be done inside of sort because datachanged has already
1702 // fired and will trigger a repaint of the bound view.
1703 doSort: function(sorterFn) {
1705 if (me.remoteSort) {
1706 //the load function will pick up the new sorters and request the sorted data from the proxy
1709 me.data.sortBy(sorterFn);
1711 var range = me.getRange(),
1714 for (; i < ln; i++) {
1718 me.fireEvent('datachanged', me);
1723 * Finds the index of the first matching Record in this store by a specific field value.
1724 * @param {String} fieldName The name of the Record field to test.
1725 * @param {String/RegExp} value Either a string that the field value
1726 * should begin with, or a RegExp to test against the field.
1727 * @param {Number} startIndex (optional) The index to start searching at
1728 * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1729 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1730 * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false.
1731 * @return {Number} The matched index or -1
1733 find: function(property, value, start, anyMatch, caseSensitive, exactMatch) {
1734 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive, exactMatch);
1735 return fn ? this.data.findIndexBy(fn, null, start) : -1;
1739 * Finds the first matching Record in this store by a specific field value.
1740 * @param {String} fieldName The name of the Record field to test.
1741 * @param {String/RegExp} value Either a string that the field value
1742 * should begin with, or a RegExp to test against the field.
1743 * @param {Number} startIndex (optional) The index to start searching at
1744 * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1745 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1746 * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false.
1747 * @return {Ext.data.Model} The matched record or null
1749 findRecord: function() {
1751 index = me.find.apply(me, arguments);
1752 return index !== -1 ? me.getAt(index) : null;
1757 * Returns a filter function used to test a the given property's value. Defers most of the work to
1758 * Ext.util.MixedCollection's createValueMatcher function
1759 * @param {String} property The property to create the filter function for
1760 * @param {String/RegExp} value The string/regex to compare the property value to
1761 * @param {Boolean} anyMatch True if we don't care if the filter value is not the full value (defaults to false)
1762 * @param {Boolean} caseSensitive True to create a case-sensitive regex (defaults to false)
1763 * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false.
1764 * Ignored if anyMatch is true.
1766 createFilterFn: function(property, value, anyMatch, caseSensitive, exactMatch) {
1767 if (Ext.isEmpty(value)) {
1770 value = this.data.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
1771 return function(r) {
1772 return value.test(r.data[property]);
1777 * Finds the index of the first matching Record in this store by a specific field value.
1778 * @param {String} fieldName The name of the Record field to test.
1779 * @param {Mixed} value The value to match the field against.
1780 * @param {Number} startIndex (optional) The index to start searching at
1781 * @return {Number} The matched index or -1
1783 findExact: function(property, value, start) {
1784 return this.data.findIndexBy(function(rec) {
1785 return rec.get(property) === value;
1791 * Find the index of the first matching Record in this Store by a function.
1792 * If the function returns <tt>true</tt> it is considered a match.
1793 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1794 * <li><b>record</b> : Ext.data.Model<p class="sub-desc">The {@link Ext.data.Model record}
1795 * to test for filtering. Access field values using {@link Ext.data.Model#get}.</p></li>
1796 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1798 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1799 * @param {Number} startIndex (optional) The index to start searching at
1800 * @return {Number} The matched index or -1
1802 findBy: function(fn, scope, start) {
1803 return this.data.findIndexBy(fn, scope, start);
1807 * Collects unique values for a particular dataIndex from this store.
1808 * @param {String} dataIndex The property to collect
1809 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
1810 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
1811 * @return {Array} An array of the unique values
1813 collect: function(dataIndex, allowNull, bypassFilter) {
1815 data = (bypassFilter === true && me.snapshot) ? me.snapshot: me.data;
1817 return data.collect(dataIndex, 'data', allowNull);
1821 * Gets the number of cached records.
1822 * <p>If using paging, this may not be the total size of the dataset. If the data object
1823 * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
1824 * the dataset size. <b>Note</b>: see the Important note in {@link #load}.</p>
1825 * @return {Number} The number of Records in the Store's cache.
1827 getCount: function() {
1828 return this.data.length || 0;
1832 * Returns the total number of {@link Ext.data.Model Model} instances that the {@link Ext.data.proxy.Proxy Proxy}
1833 * indicates exist. This will usually differ from {@link #getCount} when using paging - getCount returns the
1834 * number of records loaded into the Store at the moment, getTotalCount returns the number of records that
1835 * could be loaded into the Store if the Store contained all data
1836 * @return {Number} The total number of Model instances available via the Proxy
1838 getTotalCount: function() {
1839 return this.totalCount;
1843 * Get the Record at the specified index.
1844 * @param {Number} index The index of the Record to find.
1845 * @return {Ext.data.Model} The Record at the passed index. Returns undefined if not found.
1847 getAt: function(index) {
1848 return this.data.getAt(index);
1852 * Returns a range of Records between specified indices.
1853 * @param {Number} startIndex (optional) The starting index (defaults to 0)
1854 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
1855 * @return {Ext.data.Model[]} An array of Records
1857 getRange: function(start, end) {
1858 return this.data.getRange(start, end);
1862 * Get the Record with the specified id.
1863 * @param {String} id The id of the Record to find.
1864 * @return {Ext.data.Model} The Record with the passed id. Returns undefined if not found.
1866 getById: function(id) {
1867 return (this.snapshot || this.data).findBy(function(record) {
1868 return record.getId() === id;
1873 * Get the index within the cache of the passed Record.
1874 * @param {Ext.data.Model} record The Ext.data.Model object to find.
1875 * @return {Number} The index of the passed Record. Returns -1 if not found.
1877 indexOf: function(record) {
1878 return this.data.indexOf(record);
1883 * Get the index within the entire dataset. From 0 to the totalCount.
1884 * @param {Ext.data.Model} record The Ext.data.Model object to find.
1885 * @return {Number} The index of the passed Record. Returns -1 if not found.
1887 indexOfTotal: function(record) {
1888 return record.index || this.indexOf(record);
1892 * Get the index within the cache of the Record with the passed id.
1893 * @param {String} id The id of the Record to find.
1894 * @return {Number} The index of the Record. Returns -1 if not found.
1896 indexOfId: function(id) {
1897 return this.data.indexOfKey(id);
1901 * Remove all items from the store.
1902 * @param {Boolean} silent Prevent the `clear` event from being fired.
1904 removeAll: function(silent) {
1909 me.snapshot.clear();
1911 if (silent !== true) {
1912 me.fireEvent('clear', me);
1917 * Aggregation methods
1921 * Convenience function for getting the first model instance in the store
1922 * @param {Boolean} grouped (Optional) True to perform the operation for each group
1923 * in the store. The value returned will be an object literal with the key being the group
1924 * name and the first record being the value. The grouped parameter is only honored if
1925 * the store has a groupField.
1926 * @return {Ext.data.Model/undefined} The first model instance in the store, or undefined
1928 first: function(grouped) {
1931 if (grouped && me.isGrouped()) {
1932 return me.aggregate(function(records) {
1933 return records.length ? records[0] : undefined;
1936 return me.data.first();
1941 * Convenience function for getting the last model instance in the store
1942 * @param {Boolean} grouped (Optional) True to perform the operation for each group
1943 * in the store. The value returned will be an object literal with the key being the group
1944 * name and the last record being the value. The grouped parameter is only honored if
1945 * the store has a groupField.
1946 * @return {Ext.data.Model/undefined} The last model instance in the store, or undefined
1948 last: function(grouped) {
1951 if (grouped && me.isGrouped()) {
1952 return me.aggregate(function(records) {
1953 var len = records.length;
1954 return len ? records[len - 1] : undefined;
1957 return me.data.last();
1962 * Sums the value of <tt>property</tt> for each {@link Ext.data.Model record} between <tt>start</tt>
1963 * and <tt>end</tt> and returns the result.
1964 * @param {String} field A field in each record
1965 * @param {Boolean} grouped (Optional) True to perform the operation for each group
1966 * in the store. The value returned will be an object literal with the key being the group
1967 * name and the sum for that group being the value. The grouped parameter is only honored if
1968 * the store has a groupField.
1969 * @return {Number} The sum
1971 sum: function(field, grouped) {
1974 if (grouped && me.isGrouped()) {
1975 return me.aggregate(me.getSum, me, true, [field]);
1977 return me.getSum(me.data.items, field);
1981 // @private, see sum
1982 getSum: function(records, field) {
1985 len = records.length;
1987 for (; i < len; ++i) {
1988 total += records[i].get(field);
1995 * Gets the count of items in the store.
1996 * @param {Boolean} grouped (Optional) True to perform the operation for each group
1997 * in the store. The value returned will be an object literal with the key being the group
1998 * name and the count for each group being the value. The grouped parameter is only honored if
1999 * the store has a groupField.
2000 * @return {Number} the count
2002 count: function(grouped) {
2005 if (grouped && me.isGrouped()) {
2006 return me.aggregate(function(records) {
2007 return records.length;
2010 return me.getCount();
2015 * Gets the minimum value in the store.
2016 * @param {String} field The field in each record
2017 * @param {Boolean} grouped (Optional) True to perform the operation for each group
2018 * in the store. The value returned will be an object literal with the key being the group
2019 * name and the minimum in the group being the value. The grouped parameter is only honored if
2020 * the store has a groupField.
2021 * @return {Mixed/undefined} The minimum value, if no items exist, undefined.
2023 min: function(field, grouped) {
2026 if (grouped && me.isGrouped()) {
2027 return me.aggregate(me.getMin, me, true, [field]);
2029 return me.getMin(me.data.items, field);
2033 // @private, see min
2034 getMin: function(records, field){
2036 len = records.length,
2040 min = records[0].get(field);
2043 for (; i < len; ++i) {
2044 value = records[i].get(field);
2053 * Gets the maximum value in the store.
2054 * @param {String} field The field in each record
2055 * @param {Boolean} grouped (Optional) True to perform the operation for each group
2056 * in the store. The value returned will be an object literal with the key being the group
2057 * name and the maximum in the group being the value. The grouped parameter is only honored if
2058 * the store has a groupField.
2059 * @return {Mixed/undefined} The maximum value, if no items exist, undefined.
2061 max: function(field, grouped) {
2064 if (grouped && me.isGrouped()) {
2065 return me.aggregate(me.getMax, me, true, [field]);
2067 return me.getMax(me.data.items, field);
2071 // @private, see max
2072 getMax: function(records, field) {
2074 len = records.length,
2079 max = records[0].get(field);
2082 for (; i < len; ++i) {
2083 value = records[i].get(field);
2092 * Gets the average value in the store.
2093 * @param {String} field The field in each record
2094 * @param {Boolean} grouped (Optional) True to perform the operation for each group
2095 * in the store. The value returned will be an object literal with the key being the group
2096 * name and the group average being the value. The grouped parameter is only honored if
2097 * the store has a groupField.
2098 * @return {Mixed/undefined} The average value, if no items exist, 0.
2100 average: function(field, grouped) {
2102 if (grouped && me.isGrouped()) {
2103 return me.aggregate(me.getAverage, me, true, [field]);
2105 return me.getAverage(me.data.items, field);
2109 // @private, see average
2110 getAverage: function(records, field) {
2112 len = records.length,
2115 if (records.length > 0) {
2116 for (; i < len; ++i) {
2117 sum += records[i].get(field);
2125 * Runs the aggregate function for all the records in the store.
2126 * @param {Function} fn The function to execute. The function is called with a single parameter,
2127 * an array of records for that group.
2128 * @param {Object} scope (optional) The scope to execute the function in. Defaults to the store.
2129 * @param {Boolean} grouped (Optional) True to perform the operation for each group
2130 * in the store. The value returned will be an object literal with the key being the group
2131 * name and the group average being the value. The grouped parameter is only honored if
2132 * the store has a groupField.
2133 * @param {Array} args (optional) Any arguments to append to the function call
2134 * @return {Object} An object literal with the group names and their appropriate values.
2136 aggregate: function(fn, scope, grouped, args) {
2138 if (grouped && this.isGrouped()) {
2139 var groups = this.getGroups(),
2141 len = groups.length,
2145 for (; i < len; ++i) {
2147 out[group.name] = fn.apply(scope || this, [group.children].concat(args));
2151 return fn.apply(scope || this, [this.data.items].concat(args));