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.Store"></div>/**
10 * @class Ext.data.Store
11 * @extends Ext.util.Observable
12 * <p>The Store class encapsulates a client side cache of {@link Ext.data.Record Record}
13 * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},
14 * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.</p>
15 * <p><u>Retrieving Data</u></p>
16 * <p>A Store object may access a data object using:<div class="mdetail-params"><ul>
17 * <li>{@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}</li>
18 * <li>{@link #data} to automatically pass in data</li>
19 * <li>{@link #loadData} to manually pass in data</li>
21 * <p><u>Reading Data</u></p>
22 * <p>A Store object has no inherent knowledge of the format of the data object (it could be
23 * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation}
24 * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data
26 * <p><u>Store Types</u></p>
27 * <p>There are several implementations of Store available which are customized for use with
28 * a specific DataReader implementation. Here is an example using an ArrayStore which implicitly
29 * creates a reader commensurate to an Array data object.</p>
31 var myStore = new Ext.data.ArrayStore({
32 fields: ['fullname', 'first'],
33 idIndex: 0 // id for each record will be the first element
36 * <p>For custom implementations create a basic {@link Ext.data.Store} configured as needed:</p>
38 // create a {@link Ext.data.Record Record} constructor:
39 var rt = Ext.data.Record.create([
43 var myStore = new Ext.data.Store({
44 // explicitly create reader
45 reader: new Ext.data.ArrayReader(
47 idIndex: 0 // id for each record will be the first element
53 * <p>Load some data into store (note the data object is an array which corresponds to the reader):</p>
56 [1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
57 [2, 'Barney Rubble', 'Barney']
59 myStore.loadData(myData);
61 * <p>Records are cached and made available through accessor functions. An example of adding
62 * a record to the store:</p>
65 fullname: 'Full Name',
68 var recId = 100; // provide unique id for the record
69 var r = new myStore.recordType(defaultData, ++recId); // create new record
70 myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add})
72 * <p><u>Writing Data</u></p>
73 * <p>And <b>new in Ext version 3</b>, use the new {@link Ext.data.DataWriter DataWriter} to create an automated, <a href="http://extjs.com/deploy/dev/examples/writer/writer.html">Writable Store</a>
74 * along with <a href="http://extjs.com/deploy/dev/examples/restful/restful.html">RESTful features.</a>
76 * Creates a new Store.
77 * @param {Object} config A config object containing the objects needed for the Store to access data,
78 * and read the data into Records.
81 Ext.data.Store = Ext.extend(Ext.util.Observable, {
82 <div id="cfg-Ext.data.Store-storeId"></div>/**
83 * @cfg {String} storeId If passed, the id to use to register with the <b>{@link Ext.StoreMgr StoreMgr}</b>.
84 * <p><b>Note</b>: if a (deprecated) <tt>{@link #id}</tt> is specified it will supersede the <tt>storeId</tt>
87 <div id="cfg-Ext.data.Store-url"></div>/**
88 * @cfg {String} url If a <tt>{@link #proxy}</tt> is not specified the <tt>url</tt> will be used to
89 * implicitly configure a {@link Ext.data.HttpProxy HttpProxy} if an <tt>url</tt> is specified.
90 * Typically this option, or the <code>{@link #data}</code> option will be specified.
92 <div id="cfg-Ext.data.Store-autoLoad"></div>/**
93 * @cfg {Boolean/Object} autoLoad If <tt>{@link #data}</tt> is not specified, and if <tt>autoLoad</tt>
94 * is <tt>true</tt> or an <tt>Object</tt>, this store's {@link #load} method is automatically called
95 * after creation. If the value of <tt>autoLoad</tt> is an <tt>Object</tt>, this <tt>Object</tt> will
96 * be passed to the store's {@link #load} method.
98 <div id="cfg-Ext.data.Store-proxy"></div>/**
99 * @cfg {Ext.data.DataProxy} proxy The {@link Ext.data.DataProxy DataProxy} object which provides
100 * access to a data object. See <code>{@link #url}</code>.
102 <div id="cfg-Ext.data.Store-data"></div>/**
103 * @cfg {Array} data An inline data object readable by the <code>{@link #reader}</code>.
104 * Typically this option, or the <code>{@link #url}</code> option will be specified.
106 <div id="cfg-Ext.data.Store-reader"></div>/**
107 * @cfg {Ext.data.DataReader} reader The {@link Ext.data.DataReader Reader} object which processes the
108 * data object and returns an Array of {@link Ext.data.Record} objects which are cached keyed by their
109 * <b><tt>{@link Ext.data.Record#id id}</tt></b> property.
111 <div id="cfg-Ext.data.Store-writer"></div>/**
112 * @cfg {Ext.data.DataWriter} writer
113 * <p>The {@link Ext.data.DataWriter Writer} object which processes a record object for being written
114 * to the server-side database.</p>
115 * <br><p>When a writer is installed into a Store the {@link #add}, {@link #remove}, and {@link #update}
116 * events on the store are monitored in order to remotely {@link #createRecords create records},
117 * {@link #destroyRecord destroy records}, or {@link #updateRecord update records}.</p>
118 * <br><p>The proxy for this store will relay any {@link #writexception} events to this store.</p>
119 * <br><p>Sample implementation:
121 var writer = new {@link Ext.data.JsonWriter}({
123 writeAllFields: true // write all fields, not just those that changed
126 // Typical Store collecting the Proxy, Reader and Writer together.
127 var store = new Ext.data.Store({
132 writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
134 autoSave: false // <-- false to delay executing create, update, destroy requests
135 // until specifically told to do so.
140 <div id="cfg-Ext.data.Store-baseParams"></div>/**
141 * @cfg {Object} baseParams
142 * <p>An object containing properties which are to be sent as parameters
143 * for <i>every</i> HTTP request.</p>
144 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
145 * <p><b>Note</b>: <code>baseParams</code> may be superseded by any <code>params</code>
146 * specified in a <code>{@link #load}</code> request, see <code>{@link #load}</code>
147 * for more details.</p>
148 * This property may be modified after creation using the <code>{@link #setBaseParam}</code>
152 <div id="cfg-Ext.data.Store-sortInfo"></div>/**
153 * @cfg {Object} sortInfo A config object to specify the sort order in the request of a Store's
154 * {@link #load} operation. Note that for local sorting, the <tt>direction</tt> property is
155 * case-sensitive. See also {@link #remoteSort} and {@link #paramNames}.
156 * For example:<pre><code>
159 direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
163 <div id="cfg-Ext.data.Store-remoteSort"></div>/**
164 * @cfg {boolean} remoteSort <tt>true</tt> if sorting is to be handled by requesting the <tt>{@link #proxy Proxy}</tt>
165 * to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
166 * in place (defaults to <tt>false</tt>).
167 * <p>If <tt>remoteSort</tt> is <tt>true</tt>, then clicking on a {@link Ext.grid.Column Grid Column}'s
168 * {@link Ext.grid.Column#header header} causes the current page to be requested from the server appending
169 * the following two parameters to the <b><tt>{@link #load params}</tt></b>:<div class="mdetail-params"><ul>
170 * <li><b><tt>sort</tt></b> : String<p class="sub-desc">The <tt>name</tt> (as specified in the Record's
171 * {@link Ext.data.Field Field definition}) of the field to sort on.</p></li>
172 * <li><b><tt>dir</tt></b> : String<p class="sub-desc">The direction of the sort, 'ASC' or 'DESC' (case-sensitive).</p></li>
177 <div id="cfg-Ext.data.Store-autoDestroy"></div>/**
178 * @cfg {Boolean} autoDestroy <tt>true</tt> to destroy the store when the component the store is bound
179 * to is destroyed (defaults to <tt>false</tt>).
180 * <p><b>Note</b>: this should be set to true when using stores that are bound to only 1 component.</p>
184 <div id="cfg-Ext.data.Store-pruneModifiedRecords"></div>/**
185 * @cfg {Boolean} pruneModifiedRecords <tt>true</tt> to clear all modified record information each time
186 * the store is loaded or when a record is removed (defaults to <tt>false</tt>). See {@link #getModifiedRecords}
187 * for the accessor method to retrieve the modified records.
189 pruneModifiedRecords : false,
191 <div id="prop-Ext.data.Store-lastOptions"></div>/**
192 * Contains the last options object used as the parameter to the {@link #load} method. See {@link #load}
193 * for the details of what this may contain. This may be useful for accessing any params which were used
194 * to load the current Record cache.
199 <div id="cfg-Ext.data.Store-autoSave"></div>/**
200 * @cfg {Boolean} autoSave
201 * <p>Defaults to <tt>true</tt> causing the store to automatically {@link #save} records to
202 * the server when a record is modified (ie: becomes 'dirty'). Specify <tt>false</tt> to manually call {@link #save}
203 * to send all modifiedRecords to the server.</p>
204 * <br><p><b>Note</b>: each CRUD action will be sent as a separate request.</p>
208 <div id="cfg-Ext.data.Store-batch"></div>/**
209 * @cfg {Boolean} batch
210 * <p>Defaults to <tt>true</tt> (unless <code>{@link #restful}:true</code>). Multiple
211 * requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) will be combined
212 * and sent as one transaction. Only applies when <code>{@link #autoSave}</code> is set
213 * to <tt>false</tt>.</p>
214 * <br><p>If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is
215 * generated for each record.</p>
219 <div id="cfg-Ext.data.Store-restful"></div>/**
220 * @cfg {Boolean} restful
221 * Defaults to <tt>false</tt>. Set to <tt>true</tt> to have the Store and the set
222 * Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
223 * PUT and DELETE requests to the server. The HTTP method used for any given CRUD
224 * action is described in {@link Ext.data.Api#restActions}. For additional information
225 * see {@link Ext.data.DataProxy#restful}.
226 * <p><b>Note</b>: if <code>{@link #restful}:true</code> <code>batch</code> will
227 * internally be set to <tt>false</tt>.</p>
231 <div id="cfg-Ext.data.Store-paramNames"></div>/**
232 * @cfg {Object} paramNames
233 * <p>An object containing properties which specify the names of the paging and
234 * sorting parameters passed to remote servers when loading blocks of data. By default, this
235 * object takes the following form:</p><pre><code>
237 start : 'start', // The parameter name which specifies the start row
238 limit : 'limit', // The parameter name which specifies number of rows to return
239 sort : 'sort', // The parameter name which specifies the column to sort on
240 dir : 'dir' // The parameter name which specifies the sort direction
243 * <p>The server must produce the requested data block upon receipt of these parameter names.
244 * If different parameter names are required, this property can be overriden using a configuration
246 * <p>A {@link Ext.PagingToolbar PagingToolbar} bound to this Store uses this property to determine
247 * the parameter names to use in its {@link #load requests}.
249 paramNames : undefined,
251 <div id="cfg-Ext.data.Store-defaultParamNames"></div>/**
252 * @cfg {Object} defaultParamNames
253 * Provides the default values for the {@link #paramNames} property. To globally modify the parameters
254 * for all stores, this object should be changed on the store prototype.
256 defaultParamNames : {
264 batchKey : '_ext_batch_',
266 constructor : function(config){
267 this.data = new Ext.util.MixedCollection(false);
268 this.data.getKey = function(o){
271 <div id="prop-Ext.data.Store-baseParams"></div>/**
272 * See the <code>{@link #baseParams corresponding configuration option}</code>
273 * for a description of this property.
274 * To modify this property see <code>{@link #setBaseParam}</code>.
277 this.baseParams = {};
279 // temporary removed-records cache
282 if(config && config.data){
283 this.inlineData = config.data;
287 Ext.apply(this, config);
289 this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
291 if((this.url || this.api) && !this.proxy){
292 this.proxy = new Ext.data.HttpProxy({url: this.url, api: this.api});
294 // If Store is RESTful, so too is the DataProxy
295 if (this.restful === true && this.proxy) {
296 // When operating RESTfully, a unique transaction is generated for each record.
297 // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
299 Ext.data.Api.restify(this.proxy);
302 if(this.reader){ // reader passed
303 if(!this.recordType){
304 this.recordType = this.reader.recordType;
306 if(this.reader.onMetaChange){
307 this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
309 if (this.writer) { // writer passed
310 if (this.writer instanceof(Ext.data.DataWriter) === false) { // <-- config-object instead of instance.
311 this.writer = this.buildWriter(this.writer);
313 this.writer.meta = this.reader.meta;
314 this.pruneModifiedRecords = true;
318 <div id="prop-Ext.data.Store-recordType"></div>/**
319 * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
320 * {@link Ext.data.DataReader Reader}. Read-only.
321 * <p>If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
322 * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
323 * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).</p>
324 * <p>This property may be used to create new Records of the type held in this Store, for example:</p><pre><code>
325 // create the data store
326 var store = new Ext.data.ArrayStore({
330 {name: 'price', type: 'float'},
331 {name: 'change', type: 'float'},
332 {name: 'pctChange', type: 'float'},
333 {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
336 store.loadData(myData);
339 var grid = new Ext.grid.EditorGridPanel({
341 colModel: new Ext.grid.ColumnModel({
343 {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
344 {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
345 {header: 'Change', renderer: change, dataIndex: 'change'},
346 {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
347 {header: 'Last Updated', width: 85,
348 renderer: Ext.util.Format.dateRenderer('m/d/Y'),
349 dataIndex: 'lastChange'}
356 autoExpandColumn: 'company', // match the id specified in the column model
362 handler : function(){
365 company: 'New Company',
366 lastChange: (new Date()).clearTime(),
370 var recId = 3; // provide unique id
371 var p = new store.recordType(defaultData, recId); // create new record
373 store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
374 grid.startEditing(0, 0);
379 * @property recordType
384 <div id="prop-Ext.data.Store-fields"></div>/**
385 * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
386 * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
388 * @type Ext.util.MixedCollection
390 this.fields = this.recordType.prototype.fields;
395 <div id="event-Ext.data.Store-datachanged"></div>/**
397 * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
398 * widget that is using this Store as a Record cache should refresh its view.
399 * @param {Store} this
402 <div id="event-Ext.data.Store-metachange"></div>/**
404 * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
405 * @param {Store} this
406 * @param {Object} meta The JSON metadata
409 <div id="event-Ext.data.Store-add"></div>/**
411 * Fires when Records have been {@link #add}ed to the Store
412 * @param {Store} this
413 * @param {Ext.data.Record[]} records The array of Records added
414 * @param {Number} index The index at which the record(s) were added
417 <div id="event-Ext.data.Store-remove"></div>/**
419 * Fires when a Record has been {@link #remove}d from the Store
420 * @param {Store} this
421 * @param {Ext.data.Record} record The Record that was removed
422 * @param {Number} index The index at which the record was removed
425 <div id="event-Ext.data.Store-update"></div>/**
427 * Fires when a Record has been updated
428 * @param {Store} this
429 * @param {Ext.data.Record} record The Record that was updated
430 * @param {String} operation The update operation being performed. Value may be one of:
433 Ext.data.Record.REJECT
434 Ext.data.Record.COMMIT
438 <div id="event-Ext.data.Store-clear"></div>/**
440 * Fires when the data cache has been cleared.
441 * @param {Store} this
442 * @param {Record[]} The records that were cleared.
445 <div id="event-Ext.data.Store-exception"></div>/**
447 * <p>Fires if an exception occurs in the Proxy during a remote request.
448 * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
449 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
450 * for additional details.
451 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
455 <div id="event-Ext.data.Store-beforeload"></div>/**
457 * Fires before a request is made for a new data object. If the beforeload handler returns
458 * <tt>false</tt> the {@link #load} action will be canceled.
459 * @param {Store} this
460 * @param {Object} options The loading options that were specified (see {@link #load} for details)
463 <div id="event-Ext.data.Store-load"></div>/**
465 * Fires after a new set of Records has been loaded.
466 * @param {Store} this
467 * @param {Ext.data.Record[]} records The Records that were loaded
468 * @param {Object} options The loading options that were specified (see {@link #load} for details)
471 <div id="event-Ext.data.Store-loadexception"></div>/**
472 * @event loadexception
473 * <p>This event is <b>deprecated</b> in favor of the catch-all <b><code>{@link #exception}</code></b>
475 * <p>This event is relayed through the corresponding {@link Ext.data.DataProxy}.
476 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
477 * for additional details.
478 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
482 <div id="event-Ext.data.Store-beforewrite"></div>/**
484 * @param {Ext.data.Store} store
485 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
486 * @param {Record/Array[Record]} rs
487 * @param {Object} options The loading options that were specified. Edit <code>options.params</code> to add Http parameters to the request. (see {@link #save} for details)
488 * @param {Object} arg The callback's arg object passed to the {@link #request} function
491 <div id="event-Ext.data.Store-write"></div>/**
493 * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
494 * Success of the action is determined in the <code>result['successProperty']</code>property (<b>NOTE</b> for RESTful stores,
495 * a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).
496 * @param {Ext.data.Store} store
497 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
498 * @param {Object} result The 'data' picked-out out of the response for convenience.
499 * @param {Ext.Direct.Transaction} res
500 * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
503 <div id="event-Ext.data.Store-beforesave"></div>/**
505 * Fires before a save action is called. A save encompasses destroying records, updating records and creating records.
506 * @param {Ext.data.Store} store
507 * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
508 * with an array of records for each action.
511 <div id="event-Ext.data.Store-save"></div>/**
513 * Fires after a save is completed. A save encompasses destroying records, updating records and creating records.
514 * @param {Ext.data.Store} store
515 * @param {Number} batch The identifier for the batch that was saved.
516 * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
517 * with an array of records for each action.
524 // TODO remove deprecated loadexception with ext-3.0.1
525 this.relayEvents(this.proxy, ['loadexception', 'exception']);
527 // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
531 add: this.createRecords,
532 remove: this.destroyRecord,
533 update: this.updateRecord,
538 this.sortToggle = {};
540 this.setDefaultSort(this.sortField, this.sortDir);
541 }else if(this.sortInfo){
542 this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
545 Ext.data.Store.superclass.constructor.call(this);
548 this.storeId = this.id;
552 Ext.StoreMgr.register(this);
555 this.loadData(this.inlineData);
556 delete this.inlineData;
557 }else if(this.autoLoad){
558 this.load.defer(10, this, [
559 typeof this.autoLoad == 'object' ?
560 this.autoLoad : undefined]);
562 // used internally to uniquely identify a batch
563 this.batchCounter = 0;
568 * builds a DataWriter instance when Store constructor is provided with a writer config-object instead of an instace.
569 * @param {Object} config Writer configuration
570 * @return {Ext.data.DataWriter}
573 buildWriter : function(config) {
574 var klass = undefined;
575 type = (config.format || 'json').toLowerCase();
578 klass = Ext.data.JsonWriter;
581 klass = Ext.data.XmlWriter;
584 klass = Ext.data.JsonWriter;
586 return new klass(config);
589 <div id="method-Ext.data.Store-destroy"></div>/**
590 * Destroys the store.
592 destroy : function(){
593 if(!this.isDestroyed){
595 Ext.StoreMgr.unregister(this);
599 Ext.destroy(this.proxy);
600 this.reader = this.writer = null;
601 this.purgeListeners();
602 this.isDestroyed = true;
606 <div id="method-Ext.data.Store-add"></div>/**
607 * Add Records to the Store and fires the {@link #add} event. To add Records
608 * to the store from a remote source use <code>{@link #load}({add:true})</code>.
609 * See also <code>{@link #recordType}</code> and <code>{@link #insert}</code>.
610 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
611 * to add to the cache. See {@link #recordType}.
613 add : function(records){
614 records = [].concat(records);
615 if(records.length < 1){
618 for(var i = 0, len = records.length; i < len; i++){
619 records[i].join(this);
621 var index = this.data.length;
622 this.data.addAll(records);
624 this.snapshot.addAll(records);
626 this.fireEvent('add', this, records, index);
629 <div id="method-Ext.data.Store-addSorted"></div>/**
630 * (Local sort only) Inserts the passed Record into the Store at the index where it
631 * should go based on the current sort information.
632 * @param {Ext.data.Record} record
634 addSorted : function(record){
635 var index = this.findInsertIndex(record);
636 this.insert(index, record);
639 <div id="method-Ext.data.Store-remove"></div>/**
640 * Remove Records from the Store and fires the {@link #remove} event.
641 * @param {Ext.data.Record/Ext.data.Record[]} record The record object or array of records to remove from the cache.
643 remove : function(record){
644 if(Ext.isArray(record)){
645 Ext.each(record, function(r){
649 var index = this.data.indexOf(record);
652 this.data.removeAt(index);
654 if(this.pruneModifiedRecords){
655 this.modified.remove(record);
658 this.snapshot.remove(record);
661 this.fireEvent('remove', this, record, index);
665 <div id="method-Ext.data.Store-removeAt"></div>/**
666 * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
667 * @param {Number} index The index of the record to remove.
669 removeAt : function(index){
670 this.remove(this.getAt(index));
673 <div id="method-Ext.data.Store-removeAll"></div>/**
674 * Remove all Records from the Store and fires the {@link #clear} event.
675 * @param {Boolean} silent [false] Defaults to <tt>false</tt>. Set <tt>true</tt> to not fire clear event.
677 removeAll : function(silent){
679 this.each(function(rec){
684 this.snapshot.clear();
686 if(this.pruneModifiedRecords){
689 if (silent !== true) { // <-- prevents write-actions when we just want to clear a store.
690 this.fireEvent('clear', this, items);
695 onClear: function(store, records){
696 Ext.each(records, function(rec, index){
697 this.destroyRecord(this, rec, index);
701 <div id="method-Ext.data.Store-insert"></div>/**
702 * Inserts Records into the Store at the given index and fires the {@link #add} event.
703 * See also <code>{@link #add}</code> and <code>{@link #addSorted}</code>.
704 * @param {Number} index The start index at which to insert the passed Records.
705 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
707 insert : function(index, records){
708 records = [].concat(records);
709 for(var i = 0, len = records.length; i < len; i++){
710 this.data.insert(index, records[i]);
711 records[i].join(this);
714 this.snapshot.addAll(records);
716 this.fireEvent('add', this, records, index);
719 <div id="method-Ext.data.Store-indexOf"></div>/**
720 * Get the index within the cache of the passed Record.
721 * @param {Ext.data.Record} record The Ext.data.Record object to find.
722 * @return {Number} The index of the passed Record. Returns -1 if not found.
724 indexOf : function(record){
725 return this.data.indexOf(record);
728 <div id="method-Ext.data.Store-indexOfId"></div>/**
729 * Get the index within the cache of the Record with the passed id.
730 * @param {String} id The id of the Record to find.
731 * @return {Number} The index of the Record. Returns -1 if not found.
733 indexOfId : function(id){
734 return this.data.indexOfKey(id);
737 <div id="method-Ext.data.Store-getById"></div>/**
738 * Get the Record with the specified id.
739 * @param {String} id The id of the Record to find.
740 * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
742 getById : function(id){
743 return (this.snapshot || this.data).key(id);
746 <div id="method-Ext.data.Store-getAt"></div>/**
747 * Get the Record at the specified index.
748 * @param {Number} index The index of the Record to find.
749 * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
751 getAt : function(index){
752 return this.data.itemAt(index);
755 <div id="method-Ext.data.Store-getRange"></div>/**
756 * Returns a range of Records between specified indices.
757 * @param {Number} startIndex (optional) The starting index (defaults to 0)
758 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
759 * @return {Ext.data.Record[]} An array of Records
761 getRange : function(start, end){
762 return this.data.getRange(start, end);
766 storeOptions : function(o){
767 o = Ext.apply({}, o);
770 this.lastOptions = o;
774 clearData: function(){
775 this.data.each(function(rec) {
781 <div id="method-Ext.data.Store-load"></div>/**
782 * <p>Loads the Record cache from the configured <tt>{@link #proxy}</tt> using the configured <tt>{@link #reader}</tt>.</p>
783 * <br><p>Notes:</p><div class="mdetail-params"><ul>
784 * <li><b><u>Important</u></b>: loading is asynchronous! This call will return before the new data has been
785 * loaded. To perform any post-processing where information from the load call is required, specify
786 * the <tt>callback</tt> function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.</li>
787 * <li>If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the <tt>start</tt> and <tt>limit</tt>
788 * properties in the <code>options.params</code> property to establish the initial position within the
789 * dataset, and the number of Records to cache on each read from the Proxy.</li>
790 * <li>If using {@link #remoteSort remote sorting}, the configured <code>{@link #sortInfo}</code>
791 * will be automatically included with the posted parameters according to the specified
792 * <code>{@link #paramNames}</code>.</li>
794 * @param {Object} options An object containing properties which control loading options:<ul>
795 * <li><b><tt>params</tt></b> :Object<div class="sub-desc"><p>An object containing properties to pass as HTTP
796 * parameters to a remote data source. <b>Note</b>: <code>params</code> will override any
797 * <code>{@link #baseParams}</code> of the same name.</p>
798 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
799 * <li><b>callback</b> : Function<div class="sub-desc"><p>A function to be called after the Records
800 * have been loaded. The callback is called after the load event is fired, and is passed the following arguments:<ul>
801 * <li>r : Ext.data.Record[] An Array of Records loaded.</li>
802 * <li>options : Options object from the load call.</li>
803 * <li>success : Boolean success indicator.</li></ul></p></div></li>
804 * <li><b>scope</b> : Object<div class="sub-desc"><p>Scope with which to call the callback (defaults
805 * to the Store object)</p></div></li>
806 * <li><b>add</b> : Boolean<div class="sub-desc"><p>Indicator to append loaded records rather than
807 * replace the current cache. <b>Note</b>: see note for <tt>{@link #loadData}</tt></p></div></li>
809 * @return {Boolean} If the <i>developer</i> provided <tt>{@link #beforeload}</tt> event handler returns
810 * <tt>false</tt>, the load call will abort and will return <tt>false</tt>; otherwise will return <tt>true</tt>.
812 load : function(options) {
813 options = options || {};
814 this.storeOptions(options);
815 if(this.sortInfo && this.remoteSort){
816 var pn = this.paramNames;
817 options.params = options.params || {};
818 options.params[pn.sort] = this.sortInfo.field;
819 options.params[pn.dir] = this.sortInfo.direction;
822 return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
824 this.handleException(e);
830 * updateRecord Should not be used directly. This method will be called automatically if a Writer is set.
831 * Listens to 'update' event.
832 * @param {Object} store
833 * @param {Object} record
834 * @param {Object} action
837 updateRecord : function(store, record, action) {
838 if (action == Ext.data.Record.EDIT && this.autoSave === true && (!record.phantom || (record.phantom && record.isValid()))) {
844 * Should not be used directly. Store#add will call this automatically if a Writer is set
845 * @param {Object} store
847 * @param {Object} index
850 createRecords : function(store, rs, index) {
851 for (var i = 0, len = rs.length; i < len; i++) {
852 if (rs[i].phantom && rs[i].isValid()) {
853 rs[i].markDirty(); // <-- Mark new records dirty
854 this.modified.push(rs[i]); // <-- add to modified
857 if (this.autoSave === true) {
863 * Destroys a record or records. Should not be used directly. It's called by Store#remove if a Writer is set.
864 * @param {Store} this
865 * @param {Ext.data.Record/Ext.data.Record[]}
866 * @param {Number} index
869 destroyRecord : function(store, record, index) {
870 if (this.modified.indexOf(record) != -1) { // <-- handled already if @cfg pruneModifiedRecords == true
871 this.modified.remove(record);
873 if (!record.phantom) {
874 this.removed.push(record);
876 // since the record has already been removed from the store but the server request has not yet been executed,
877 // must keep track of the last known index this record existed. If a server error occurs, the record can be
878 // put back into the store. @see Store#createCallback where the record is returned when response status === false
879 record.lastIndex = index;
881 if (this.autoSave === true) {
888 * This method should generally not be used directly. This method is called internally
889 * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
890 * {@link #remove}, or {@link #update} events fire.
891 * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
892 * @param {Record/Record[]} rs
893 * @param {Object} options
897 execute : function(action, rs, options, /* private */ batch) {
898 // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
899 if (!Ext.data.Api.isAction(action)) {
900 throw new Ext.data.Api.Error('execute', action);
902 // make sure options has a fresh, new params hash
903 options = Ext.applyIf(options||{}, {
906 if(batch !== undefined){
907 this.addToBatch(batch);
909 // have to separate before-events since load has a different signature than create,destroy and save events since load does not
910 // include the rs (record resultset) parameter. Capture return values from the beforeaction into doRequest flag.
911 var doRequest = true;
913 if (action === 'read') {
914 Ext.applyIf(options.params, this.baseParams);
915 doRequest = this.fireEvent('beforeload', this, options);
918 // if Writer is configured as listful, force single-record rs to be [{}] instead of {}
919 // TODO Move listful rendering into DataWriter where the @cfg is defined. Should be easy now.
920 if (this.writer.listful === true && this.restful !== true) {
921 rs = (Ext.isArray(rs)) ? rs : [rs];
923 // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
924 else if (Ext.isArray(rs) && rs.length == 1) {
927 // Write the action to options.params
928 if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
929 this.writer.apply(options.params, this.baseParams, action, rs);
932 if (doRequest !== false) {
933 // Send request to proxy.
934 if (this.writer && this.proxy.url && !this.proxy.restful && !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
935 options.params.xaction = action; // <-- really old, probaby unecessary.
937 // Note: Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions.
938 // We'll flip it now and send the value into DataProxy#request, since it's the value which maps to
939 // the user's configured DataProxy#api
940 // TODO Refactor all Proxies to accept an instance of Ext.data.Request (not yet defined) instead of this looooooong list
941 // of params. This method is an artifact from Ext2.
942 this.proxy.request(Ext.data.Api.actions[action], rs, options.params, this.reader, this.createCallback(action, rs, batch), this, options);
947 <div id="method-Ext.data.Store-save"></div>/**
948 * Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
949 * the configured <code>{@link #url}</code> will be used.
952 * --------------- --------------------
953 * removed records Ext.data.Api.actions.destroy
954 * phantom records Ext.data.Api.actions.create
955 * {@link #getModifiedRecords modified records} Ext.data.Api.actions.update
957 * @TODO: Create extensions of Error class and send associated Record with thrown exceptions.
958 * e.g.: Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
959 * @return {Number} batch Returns a number to uniquely identify the "batch" of saves occurring. -1 will be returned
960 * if there are no items to save or the save was cancelled.
964 throw new Ext.data.Store.Error('writer-undefined');
972 // DESTROY: First check for removed records. Records in this.removed are guaranteed non-phantoms. @see Store#remove
973 if(this.removed.length){
974 queue.push(['destroy', this.removed]);
977 // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
978 var rs = [].concat(this.getModifiedRecords());
980 // CREATE: Next check for phantoms within rs. splice-off and execute create.
982 for(var i = rs.length-1; i >= 0; i--){
983 if(rs[i].phantom === true){
984 var rec = rs.splice(i, 1).shift();
988 }else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
992 // If we have valid phantoms, create them...
994 queue.push(['create', phantoms]);
997 // UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
999 queue.push(['update', rs]);
1004 batch = ++this.batchCounter;
1005 for(var i = 0; i < len; ++i){
1007 data[trans[0]] = trans[1];
1009 if(this.fireEvent('beforesave', this, data) !== false){
1010 for(var i = 0; i < len; ++i){
1012 this.doTransaction(trans[0], trans[1], batch);
1020 // private. Simply wraps call to Store#execute in try/catch. Defers to Store#handleException on error. Loops if batch: false
1021 doTransaction : function(action, rs, batch) {
1022 function transaction(records) {
1024 this.execute(action, records, undefined, batch);
1026 this.handleException(e);
1029 if(this.batch === false){
1030 for(var i = 0, len = rs.length; i < len; i++){
1031 transaction.call(this, rs[i]);
1034 transaction.call(this, rs);
1039 addToBatch : function(batch){
1040 var b = this.batches,
1041 key = this.batchKey + batch,
1054 removeFromBatch : function(batch, action, data){
1055 var b = this.batches,
1056 key = this.batchKey + batch,
1063 arr = o.data[action] || [];
1064 o.data[action] = arr.concat(data);
1068 this.fireEvent('save', this, batch, data);
1075 // @private callback-handler for remote CRUD actions
1076 // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
1077 createCallback : function(action, rs, batch) {
1078 var actions = Ext.data.Api.actions;
1079 return (action == 'read') ? this.loadRecords : function(data, response, success) {
1080 // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
1081 this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, [].concat(data));
1082 // If success === false here, exception will have been called in DataProxy
1083 if (success === true) {
1084 this.fireEvent('write', this, action, data, response, rs);
1086 this.removeFromBatch(batch, action, data);
1090 // Clears records from modified array after an exception event.
1091 // NOTE: records are left marked dirty. Do we want to commit them even though they were not updated/realized?
1092 // TODO remove this method?
1093 clearModified : function(rs) {
1094 if (Ext.isArray(rs)) {
1095 for (var n=rs.length-1;n>=0;n--) {
1096 this.modified.splice(this.modified.indexOf(rs[n]), 1);
1099 this.modified.splice(this.modified.indexOf(rs), 1);
1103 // remap record ids in MixedCollection after records have been realized. @see Store#onCreateRecords, @see DataReader#realize
1104 reMap : function(record) {
1105 if (Ext.isArray(record)) {
1106 for (var i = 0, len = record.length; i < len; i++) {
1107 this.reMap(record[i]);
1110 delete this.data.map[record._phid];
1111 this.data.map[record.id] = record;
1112 var index = this.data.keys.indexOf(record._phid);
1113 this.data.keys.splice(index, 1, record.id);
1114 delete record._phid;
1118 // @protected onCreateRecord proxy callback for create action
1119 onCreateRecords : function(success, rs, data) {
1120 if (success === true) {
1122 this.reader.realize(rs, data);
1126 this.handleException(e);
1127 if (Ext.isArray(rs)) {
1128 // Recurse to run back into the try {}. DataReader#realize splices-off the rs until empty.
1129 this.onCreateRecords(success, rs, data);
1135 // @protected, onUpdateRecords proxy callback for update action
1136 onUpdateRecords : function(success, rs, data) {
1137 if (success === true) {
1139 this.reader.update(rs, data);
1141 this.handleException(e);
1142 if (Ext.isArray(rs)) {
1143 // Recurse to run back into the try {}. DataReader#update splices-off the rs until empty.
1144 this.onUpdateRecords(success, rs, data);
1150 // @protected onDestroyRecords proxy callback for destroy action
1151 onDestroyRecords : function(success, rs, data) {
1152 // splice each rec out of this.removed
1153 rs = (rs instanceof Ext.data.Record) ? [rs] : [].concat(rs);
1154 for (var i=0,len=rs.length;i<len;i++) {
1155 this.removed.splice(this.removed.indexOf(rs[i]), 1);
1157 if (success === false) {
1158 // put records back into store if remote destroy fails.
1159 // @TODO: Might want to let developer decide.
1160 for (i=rs.length-1;i>=0;i--) {
1161 this.insert(rs[i].lastIndex, rs[i]); // <-- lastIndex set in Store#destroyRecord
1166 // protected handleException. Possibly temporary until Ext framework has an exception-handler.
1167 handleException : function(e) {
1168 // @see core/Error.js
1172 <div id="method-Ext.data.Store-reload"></div>/**
1173 * <p>Reloads the Record cache from the configured Proxy using the configured
1174 * {@link Ext.data.Reader Reader} and the options from the last load operation
1176 * <p><b>Note</b>: see the Important note in {@link #load}.</p>
1177 * @param {Object} options <p>(optional) An <tt>Object</tt> containing
1178 * {@link #load loading options} which may override the {@link #lastOptions options}
1179 * used in the last {@link #load} operation. See {@link #load} for details
1180 * (defaults to <tt>null</tt>, in which case the {@link #lastOptions} are
1182 * <br><p>To add new params to the existing params:</p><pre><code>
1183 lastOptions = myStore.lastOptions;
1184 Ext.apply(lastOptions.params, {
1187 myStore.reload(lastOptions);
1190 reload : function(options){
1191 this.load(Ext.applyIf(options||{}, this.lastOptions));
1195 // Called as a callback by the Reader during a load operation.
1196 loadRecords : function(o, options, success){
1197 if (this.isDestroyed === true) {
1200 if(!o || success === false){
1201 if(success !== false){
1202 this.fireEvent('load', this, [], options);
1204 if(options.callback){
1205 options.callback.call(options.scope || this, [], options, false, o);
1209 var r = o.records, t = o.totalRecords || r.length;
1210 if(!options || options.add !== true){
1211 if(this.pruneModifiedRecords){
1214 for(var i = 0, len = r.length; i < len; i++){
1218 this.data = this.snapshot;
1219 delete this.snapshot;
1222 this.data.addAll(r);
1223 this.totalLength = t;
1225 this.fireEvent('datachanged', this);
1227 this.totalLength = Math.max(t, this.data.length+r.length);
1230 this.fireEvent('load', this, r, options);
1231 if(options.callback){
1232 options.callback.call(options.scope || this, r, options, true);
1236 <div id="method-Ext.data.Store-loadData"></div>/**
1237 * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
1238 * which understands the format of the data must have been configured in the constructor.
1239 * @param {Object} data The data block from which to read the Records. The format of the data expected
1240 * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
1241 * that {@link Ext.data.Reader Reader}'s <tt>{@link Ext.data.Reader#readRecords}</tt> parameter.
1242 * @param {Boolean} append (Optional) <tt>true</tt> to append the new Records rather the default to replace
1243 * the existing cache.
1244 * <b>Note</b>: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
1245 * with ids which are already present in the Store will <i>replace</i> existing Records. Only Records with
1246 * new, unique ids will be added.
1248 loadData : function(o, append){
1249 var r = this.reader.readRecords(o);
1250 this.loadRecords(r, {add: append}, true);
1253 <div id="method-Ext.data.Store-getCount"></div>/**
1254 * Gets the number of cached records.
1255 * <p>If using paging, this may not be the total size of the dataset. If the data object
1256 * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
1257 * the dataset size. <b>Note</b>: see the Important note in {@link #load}.</p>
1258 * @return {Number} The number of Records in the Store's cache.
1260 getCount : function(){
1261 return this.data.length || 0;
1264 <div id="method-Ext.data.Store-getTotalCount"></div>/**
1265 * Gets the total number of records in the dataset as returned by the server.
1266 * <p>If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
1267 * must contain the dataset size. For remote data sources, the value for this property
1268 * (<tt>totalProperty</tt> for {@link Ext.data.JsonReader JsonReader},
1269 * <tt>totalRecords</tt> for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
1270 * <b>Note</b>: see the Important note in {@link #load}.</p>
1271 * @return {Number} The number of Records as specified in the data object passed to the Reader
1273 * <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
1275 getTotalCount : function(){
1276 return this.totalLength || 0;
1279 <div id="method-Ext.data.Store-getSortState"></div>/**
1280 * Returns an object describing the current sort state of this Store.
1281 * @return {Object} The sort state of the Store. An object with two properties:<ul>
1282 * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>
1283 * <li><b>direction : String<p class="sub-desc">The sort order, 'ASC' or 'DESC' (case-sensitive).</p></li>
1285 * See <tt>{@link #sortInfo}</tt> for additional details.
1287 getSortState : function(){
1288 return this.sortInfo;
1292 applySort : function(){
1293 if(this.sortInfo && !this.remoteSort){
1294 var s = this.sortInfo, f = s.field;
1295 this.sortData(f, s.direction);
1300 sortData : function(f, direction){
1301 direction = direction || 'ASC';
1302 var st = this.fields.get(f).sortType;
1303 var fn = function(r1, r2){
1304 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
1305 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
1307 this.data.sort(direction, fn);
1308 if(this.snapshot && this.snapshot != this.data){
1309 this.snapshot.sort(direction, fn);
1313 <div id="method-Ext.data.Store-setDefaultSort"></div>/**
1314 * Sets the default sort column and order to be used by the next {@link #load} operation.
1315 * @param {String} fieldName The name of the field to sort by.
1316 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1318 setDefaultSort : function(field, dir){
1319 dir = dir ? dir.toUpperCase() : 'ASC';
1320 this.sortInfo = {field: field, direction: dir};
1321 this.sortToggle[field] = dir;
1324 <div id="method-Ext.data.Store-sort"></div>/**
1326 * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
1327 * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
1328 * @param {String} fieldName The name of the field to sort by.
1329 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1331 sort : function(fieldName, dir){
1332 var f = this.fields.get(fieldName);
1337 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
1338 dir = (this.sortToggle[f.name] || 'ASC').toggle('ASC', 'DESC');
1343 var st = (this.sortToggle) ? this.sortToggle[f.name] : null;
1344 var si = (this.sortInfo) ? this.sortInfo : null;
1346 this.sortToggle[f.name] = dir;
1347 this.sortInfo = {field: f.name, direction: dir};
1348 if(!this.remoteSort){
1350 this.fireEvent('datachanged', this);
1352 if (!this.load(this.lastOptions)) {
1354 this.sortToggle[f.name] = st;
1363 <div id="method-Ext.data.Store-each"></div>/**
1364 * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
1365 * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
1366 * Returning <tt>false</tt> aborts and exits the iteration.
1367 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed.
1368 * Defaults to the current {@link Ext.data.Record Record} in the iteration.
1370 each : function(fn, scope){
1371 this.data.each(fn, scope);
1374 <div id="method-Ext.data.Store-getModifiedRecords"></div>/**
1375 * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are
1376 * persisted across load operations (e.g., during paging). <b>Note</b>: deleted records are not
1377 * included. See also <tt>{@link #pruneModifiedRecords}</tt> and
1378 * {@link Ext.data.Record}<tt>{@link Ext.data.Record#markDirty markDirty}.</tt>.
1379 * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
1380 * modifications. To obtain modified fields within a modified record see
1381 *{@link Ext.data.Record}<tt>{@link Ext.data.Record#modified modified}.</tt>.
1383 getModifiedRecords : function(){
1384 return this.modified;
1388 createFilterFn : function(property, value, anyMatch, caseSensitive){
1389 if(Ext.isEmpty(value, false)){
1392 value = this.data.createValueMatcher(value, anyMatch, caseSensitive);
1394 return value.test(r.data[property]);
1398 <div id="method-Ext.data.Store-sum"></div>/**
1399 * Sums the value of <tt>property</tt> for each {@link Ext.data.Record record} between <tt>start</tt>
1400 * and <tt>end</tt> and returns the result.
1401 * @param {String} property A field in each record
1402 * @param {Number} start (optional) The record index to start at (defaults to <tt>0</tt>)
1403 * @param {Number} end (optional) The last record index to include (defaults to length - 1)
1404 * @return {Number} The sum
1406 sum : function(property, start, end){
1407 var rs = this.data.items, v = 0;
1409 end = (end || end === 0) ? end : rs.length-1;
1411 for(var i = start; i <= end; i++){
1412 v += (rs[i].data[property] || 0);
1417 <div id="method-Ext.data.Store-filter"></div>/**
1418 * Filter the {@link Ext.data.Record records} by a specified property.
1419 * @param {String} field A field on your records
1420 * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
1421 * against the field.
1422 * @param {Boolean} anyMatch (optional) <tt>true</tt> to match any part not just the beginning
1423 * @param {Boolean} caseSensitive (optional) <tt>true</tt> for case sensitive comparison
1425 filter : function(property, value, anyMatch, caseSensitive){
1426 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1427 return fn ? this.filterBy(fn) : this.clearFilter();
1430 <div id="method-Ext.data.Store-filterBy"></div>/**
1431 * Filter by a function. The specified function will be called for each
1432 * Record in this Store. If the function returns <tt>true</tt> the Record is included,
1433 * otherwise it is filtered out.
1434 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1435 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1436 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1437 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1439 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1441 filterBy : function(fn, scope){
1442 this.snapshot = this.snapshot || this.data;
1443 this.data = this.queryBy(fn, scope||this);
1444 this.fireEvent('datachanged', this);
1447 <div id="method-Ext.data.Store-query"></div>/**
1448 * Query the records by a specified property.
1449 * @param {String} field A field on your records
1450 * @param {String/RegExp} value Either a string that the field
1451 * should begin with, or a RegExp to test against the field.
1452 * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
1453 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1454 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1456 query : function(property, value, anyMatch, caseSensitive){
1457 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1458 return fn ? this.queryBy(fn) : this.data.clone();
1461 <div id="method-Ext.data.Store-queryBy"></div>/**
1462 * Query the cached records in this Store using a filtering function. The specified function
1463 * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
1464 * included in the results.
1465 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1466 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1467 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1468 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1470 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1471 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1473 queryBy : function(fn, scope){
1474 var data = this.snapshot || this.data;
1475 return data.filterBy(fn, scope||this);
1478 <div id="method-Ext.data.Store-find"></div>/**
1479 * Finds the index of the first matching Record in this store by a specific field value.
1480 * @param {String} fieldName The name of the Record field to test.
1481 * @param {String/RegExp} value Either a string that the field value
1482 * should begin with, or a RegExp to test against the field.
1483 * @param {Number} startIndex (optional) The index to start searching at
1484 * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1485 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1486 * @return {Number} The matched index or -1
1488 find : function(property, value, start, anyMatch, caseSensitive){
1489 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1490 return fn ? this.data.findIndexBy(fn, null, start) : -1;
1493 <div id="method-Ext.data.Store-findExact"></div>/**
1494 * Finds the index of the first matching Record in this store by a specific field value.
1495 * @param {String} fieldName The name of the Record field to test.
1496 * @param {Mixed} value The value to match the field against.
1497 * @param {Number} startIndex (optional) The index to start searching at
1498 * @return {Number} The matched index or -1
1500 findExact: function(property, value, start){
1501 return this.data.findIndexBy(function(rec){
1502 return rec.get(property) === value;
1506 <div id="method-Ext.data.Store-findBy"></div>/**
1507 * Find the index of the first matching Record in this Store by a function.
1508 * If the function returns <tt>true</tt> it is considered a match.
1509 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1510 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1511 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1512 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1514 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1515 * @param {Number} startIndex (optional) The index to start searching at
1516 * @return {Number} The matched index or -1
1518 findBy : function(fn, scope, start){
1519 return this.data.findIndexBy(fn, scope, start);
1522 <div id="method-Ext.data.Store-collect"></div>/**
1523 * Collects unique values for a particular dataIndex from this store.
1524 * @param {String} dataIndex The property to collect
1525 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
1526 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
1527 * @return {Array} An array of the unique values
1529 collect : function(dataIndex, allowNull, bypassFilter){
1530 var d = (bypassFilter === true && this.snapshot) ?
1531 this.snapshot.items : this.data.items;
1532 var v, sv, r = [], l = {};
1533 for(var i = 0, len = d.length; i < len; i++){
1534 v = d[i].data[dataIndex];
1536 if((allowNull || !Ext.isEmpty(v)) && !l[sv]){
1544 <div id="method-Ext.data.Store-clearFilter"></div>/**
1545 * Revert to a view of the Record cache with no filtering applied.
1546 * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
1547 * {@link #datachanged} event.
1549 clearFilter : function(suppressEvent){
1550 if(this.isFiltered()){
1551 this.data = this.snapshot;
1552 delete this.snapshot;
1553 if(suppressEvent !== true){
1554 this.fireEvent('datachanged', this);
1559 <div id="method-Ext.data.Store-isFiltered"></div>/**
1560 * Returns true if this store is currently filtered
1563 isFiltered : function(){
1564 return this.snapshot && this.snapshot != this.data;
1568 afterEdit : function(record){
1569 if(this.modified.indexOf(record) == -1){
1570 this.modified.push(record);
1572 this.fireEvent('update', this, record, Ext.data.Record.EDIT);
1576 afterReject : function(record){
1577 this.modified.remove(record);
1578 this.fireEvent('update', this, record, Ext.data.Record.REJECT);
1582 afterCommit : function(record){
1583 this.modified.remove(record);
1584 this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
1587 <div id="method-Ext.data.Store-commitChanges"></div>/**
1588 * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
1589 * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
1590 * Ext.data.Record.COMMIT.
1592 commitChanges : function(){
1593 var m = this.modified.slice(0);
1595 for(var i = 0, len = m.length; i < len; i++){
1600 <div id="method-Ext.data.Store-rejectChanges"></div>/**
1601 * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
1603 rejectChanges : function(){
1604 var m = this.modified.slice(0);
1606 for(var i = 0, len = m.length; i < len; i++){
1609 var m = this.removed.slice(0).reverse();
1611 for(var i = 0, len = m.length; i < len; i++){
1612 this.insert(m[i].lastIndex||0, m[i]);
1618 onMetaChange : function(meta){
1619 this.recordType = this.reader.recordType;
1620 this.fields = this.recordType.prototype.fields;
1621 delete this.snapshot;
1622 if(this.reader.meta.sortInfo){
1623 this.sortInfo = this.reader.meta.sortInfo;
1624 }else if(this.sortInfo && !this.fields.get(this.sortInfo.field)){
1625 delete this.sortInfo;
1628 this.writer.meta = this.reader.meta;
1631 this.fireEvent('metachange', this, this.reader.meta);
1635 findInsertIndex : function(record){
1636 this.suspendEvents();
1637 var data = this.data.clone();
1638 this.data.add(record);
1640 var index = this.data.indexOf(record);
1642 this.resumeEvents();
1646 <div id="method-Ext.data.Store-setBaseParam"></div>/**
1647 * Set the value for a property name in this store's {@link #baseParams}. Usage:</p><pre><code>
1648 myStore.setBaseParam('foo', {bar:3});
1650 * @param {String} name Name of the property to assign
1651 * @param {Mixed} value Value to assign the <tt>name</tt>d property
1653 setBaseParam : function (name, value){
1654 this.baseParams = this.baseParams || {};
1655 this.baseParams[name] = value;
1659 Ext.reg('store', Ext.data.Store);
1661 <div id="cls-Ext.data.Store.Error"></div>/**
1662 * @class Ext.data.Store.Error
1663 * @extends Ext.Error
1664 * Store Error extension.
1665 * @param {String} name
1667 Ext.data.Store.Error = Ext.extend(Ext.Error, {
1668 name: 'Ext.data.Store'
1670 Ext.apply(Ext.data.Store.Error.prototype, {
1672 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'