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){
273 // temporary removed-records cache
276 if(config && config.data){
277 this.inlineData = config.data;
281 Ext.apply(this, config);
283 <div id="prop-Ext.data.Store-baseParams"></div>/**
284 * See the <code>{@link #baseParams corresponding configuration option}</code>
285 * for a description of this property.
286 * To modify this property see <code>{@link #setBaseParam}</code>.
289 this.baseParams = Ext.isObject(this.baseParams) ? this.baseParams : {};
291 this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
293 if((this.url || this.api) && !this.proxy){
294 this.proxy = new Ext.data.HttpProxy({url: this.url, api: this.api});
296 // If Store is RESTful, so too is the DataProxy
297 if (this.restful === true && this.proxy) {
298 // When operating RESTfully, a unique transaction is generated for each record.
299 // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
301 Ext.data.Api.restify(this.proxy);
304 if(this.reader){ // reader passed
305 if(!this.recordType){
306 this.recordType = this.reader.recordType;
308 if(this.reader.onMetaChange){
309 this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
311 if (this.writer) { // writer passed
312 if (this.writer instanceof(Ext.data.DataWriter) === false) { // <-- config-object instead of instance.
313 this.writer = this.buildWriter(this.writer);
315 this.writer.meta = this.reader.meta;
316 this.pruneModifiedRecords = true;
320 <div id="prop-Ext.data.Store-recordType"></div>/**
321 * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
322 * {@link Ext.data.DataReader Reader}. Read-only.
323 * <p>If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
324 * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
325 * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).</p>
326 * <p>This property may be used to create new Records of the type held in this Store, for example:</p><pre><code>
327 // create the data store
328 var store = new Ext.data.ArrayStore({
332 {name: 'price', type: 'float'},
333 {name: 'change', type: 'float'},
334 {name: 'pctChange', type: 'float'},
335 {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
338 store.loadData(myData);
341 var grid = new Ext.grid.EditorGridPanel({
343 colModel: new Ext.grid.ColumnModel({
345 {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
346 {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
347 {header: 'Change', renderer: change, dataIndex: 'change'},
348 {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
349 {header: 'Last Updated', width: 85,
350 renderer: Ext.util.Format.dateRenderer('m/d/Y'),
351 dataIndex: 'lastChange'}
358 autoExpandColumn: 'company', // match the id specified in the column model
364 handler : function(){
367 company: 'New Company',
368 lastChange: (new Date()).clearTime(),
372 var recId = 3; // provide unique id
373 var p = new store.recordType(defaultData, recId); // create new record
375 store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
376 grid.startEditing(0, 0);
381 * @property recordType
386 <div id="prop-Ext.data.Store-fields"></div>/**
387 * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
388 * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
390 * @type Ext.util.MixedCollection
392 this.fields = this.recordType.prototype.fields;
397 <div id="event-Ext.data.Store-datachanged"></div>/**
399 * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
400 * widget that is using this Store as a Record cache should refresh its view.
401 * @param {Store} this
404 <div id="event-Ext.data.Store-metachange"></div>/**
406 * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
407 * @param {Store} this
408 * @param {Object} meta The JSON metadata
411 <div id="event-Ext.data.Store-add"></div>/**
413 * Fires when Records have been {@link #add}ed to the Store
414 * @param {Store} this
415 * @param {Ext.data.Record[]} records The array of Records added
416 * @param {Number} index The index at which the record(s) were added
419 <div id="event-Ext.data.Store-remove"></div>/**
421 * Fires when a Record has been {@link #remove}d from the Store
422 * @param {Store} this
423 * @param {Ext.data.Record} record The Record that was removed
424 * @param {Number} index The index at which the record was removed
427 <div id="event-Ext.data.Store-update"></div>/**
429 * Fires when a Record has been updated
430 * @param {Store} this
431 * @param {Ext.data.Record} record The Record that was updated
432 * @param {String} operation The update operation being performed. Value may be one of:
435 Ext.data.Record.REJECT
436 Ext.data.Record.COMMIT
440 <div id="event-Ext.data.Store-clear"></div>/**
442 * Fires when the data cache has been cleared.
443 * @param {Store} this
444 * @param {Record[]} The records that were cleared.
447 <div id="event-Ext.data.Store-exception"></div>/**
449 * <p>Fires if an exception occurs in the Proxy during a remote request.
450 * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
451 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
452 * for additional details.
453 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
457 <div id="event-Ext.data.Store-beforeload"></div>/**
459 * Fires before a request is made for a new data object. If the beforeload handler returns
460 * <tt>false</tt> the {@link #load} action will be canceled.
461 * @param {Store} this
462 * @param {Object} options The loading options that were specified (see {@link #load} for details)
465 <div id="event-Ext.data.Store-load"></div>/**
467 * Fires after a new set of Records has been loaded.
468 * @param {Store} this
469 * @param {Ext.data.Record[]} records The Records that were loaded
470 * @param {Object} options The loading options that were specified (see {@link #load} for details)
473 <div id="event-Ext.data.Store-loadexception"></div>/**
474 * @event loadexception
475 * <p>This event is <b>deprecated</b> in favor of the catch-all <b><code>{@link #exception}</code></b>
477 * <p>This event is relayed through the corresponding {@link Ext.data.DataProxy}.
478 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
479 * for additional details.
480 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
484 <div id="event-Ext.data.Store-beforewrite"></div>/**
486 * @param {Ext.data.Store} store
487 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
488 * @param {Record/Array[Record]} rs
489 * @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)
490 * @param {Object} arg The callback's arg object passed to the {@link #request} function
493 <div id="event-Ext.data.Store-write"></div>/**
495 * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
496 * Success of the action is determined in the <code>result['successProperty']</code>property (<b>NOTE</b> for RESTful stores,
497 * a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).
498 * @param {Ext.data.Store} store
499 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
500 * @param {Object} result The 'data' picked-out out of the response for convenience.
501 * @param {Ext.Direct.Transaction} res
502 * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
505 <div id="event-Ext.data.Store-beforesave"></div>/**
507 * Fires before a save action is called. A save encompasses destroying records, updating records and creating records.
508 * @param {Ext.data.Store} store
509 * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
510 * with an array of records for each action.
513 <div id="event-Ext.data.Store-save"></div>/**
515 * Fires after a save is completed. A save encompasses destroying records, updating records and creating records.
516 * @param {Ext.data.Store} store
517 * @param {Number} batch The identifier for the batch that was saved.
518 * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
519 * with an array of records for each action.
526 // TODO remove deprecated loadexception with ext-3.0.1
527 this.relayEvents(this.proxy, ['loadexception', 'exception']);
529 // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
533 add: this.createRecords,
534 remove: this.destroyRecord,
535 update: this.updateRecord,
540 this.sortToggle = {};
542 this.setDefaultSort(this.sortField, this.sortDir);
543 }else if(this.sortInfo){
544 this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
547 Ext.data.Store.superclass.constructor.call(this);
550 this.storeId = this.id;
554 Ext.StoreMgr.register(this);
557 this.loadData(this.inlineData);
558 delete this.inlineData;
559 }else if(this.autoLoad){
560 this.load.defer(10, this, [
561 typeof this.autoLoad == 'object' ?
562 this.autoLoad : undefined]);
564 // used internally to uniquely identify a batch
565 this.batchCounter = 0;
570 * builds a DataWriter instance when Store constructor is provided with a writer config-object instead of an instace.
571 * @param {Object} config Writer configuration
572 * @return {Ext.data.DataWriter}
575 buildWriter : function(config) {
576 var klass = undefined,
577 type = (config.format || 'json').toLowerCase();
580 klass = Ext.data.JsonWriter;
583 klass = Ext.data.XmlWriter;
586 klass = Ext.data.JsonWriter;
588 return new klass(config);
591 <div id="method-Ext.data.Store-destroy"></div>/**
592 * Destroys the store.
594 destroy : function(){
595 if(!this.isDestroyed){
597 Ext.StoreMgr.unregister(this);
601 Ext.destroy(this.proxy);
602 this.reader = this.writer = null;
603 this.purgeListeners();
604 this.isDestroyed = true;
608 <div id="method-Ext.data.Store-add"></div>/**
609 * Add Records to the Store and fires the {@link #add} event. To add Records
610 * to the store from a remote source use <code>{@link #load}({add:true})</code>.
611 * See also <code>{@link #recordType}</code> and <code>{@link #insert}</code>.
612 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
613 * to add to the cache. See {@link #recordType}.
615 add : function(records){
616 records = [].concat(records);
617 if(records.length < 1){
620 for(var i = 0, len = records.length; i < len; i++){
621 records[i].join(this);
623 var index = this.data.length;
624 this.data.addAll(records);
626 this.snapshot.addAll(records);
628 this.fireEvent('add', this, records, index);
631 <div id="method-Ext.data.Store-addSorted"></div>/**
632 * (Local sort only) Inserts the passed Record into the Store at the index where it
633 * should go based on the current sort information.
634 * @param {Ext.data.Record} record
636 addSorted : function(record){
637 var index = this.findInsertIndex(record);
638 this.insert(index, record);
641 <div id="method-Ext.data.Store-remove"></div>/**
642 * Remove Records from the Store and fires the {@link #remove} event.
643 * @param {Ext.data.Record/Ext.data.Record[]} record The record object or array of records to remove from the cache.
645 remove : function(record){
646 if(Ext.isArray(record)){
647 Ext.each(record, function(r){
651 var index = this.data.indexOf(record);
654 this.data.removeAt(index);
656 if(this.pruneModifiedRecords){
657 this.modified.remove(record);
660 this.snapshot.remove(record);
663 this.fireEvent('remove', this, record, index);
667 <div id="method-Ext.data.Store-removeAt"></div>/**
668 * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
669 * @param {Number} index The index of the record to remove.
671 removeAt : function(index){
672 this.remove(this.getAt(index));
675 <div id="method-Ext.data.Store-removeAll"></div>/**
676 * Remove all Records from the Store and fires the {@link #clear} event.
677 * @param {Boolean} silent [false] Defaults to <tt>false</tt>. Set <tt>true</tt> to not fire clear event.
679 removeAll : function(silent){
681 this.each(function(rec){
686 this.snapshot.clear();
688 if(this.pruneModifiedRecords){
691 if (silent !== true) { // <-- prevents write-actions when we just want to clear a store.
692 this.fireEvent('clear', this, items);
697 onClear: function(store, records){
698 Ext.each(records, function(rec, index){
699 this.destroyRecord(this, rec, index);
703 <div id="method-Ext.data.Store-insert"></div>/**
704 * Inserts Records into the Store at the given index and fires the {@link #add} event.
705 * See also <code>{@link #add}</code> and <code>{@link #addSorted}</code>.
706 * @param {Number} index The start index at which to insert the passed Records.
707 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
709 insert : function(index, records){
710 records = [].concat(records);
711 for(var i = 0, len = records.length; i < len; i++){
712 this.data.insert(index, records[i]);
713 records[i].join(this);
716 this.snapshot.addAll(records);
718 this.fireEvent('add', this, records, index);
721 <div id="method-Ext.data.Store-indexOf"></div>/**
722 * Get the index within the cache of the passed Record.
723 * @param {Ext.data.Record} record The Ext.data.Record object to find.
724 * @return {Number} The index of the passed Record. Returns -1 if not found.
726 indexOf : function(record){
727 return this.data.indexOf(record);
730 <div id="method-Ext.data.Store-indexOfId"></div>/**
731 * Get the index within the cache of the Record with the passed id.
732 * @param {String} id The id of the Record to find.
733 * @return {Number} The index of the Record. Returns -1 if not found.
735 indexOfId : function(id){
736 return this.data.indexOfKey(id);
739 <div id="method-Ext.data.Store-getById"></div>/**
740 * Get the Record with the specified id.
741 * @param {String} id The id of the Record to find.
742 * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
744 getById : function(id){
745 return (this.snapshot || this.data).key(id);
748 <div id="method-Ext.data.Store-getAt"></div>/**
749 * Get the Record at the specified index.
750 * @param {Number} index The index of the Record to find.
751 * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
753 getAt : function(index){
754 return this.data.itemAt(index);
757 <div id="method-Ext.data.Store-getRange"></div>/**
758 * Returns a range of Records between specified indices.
759 * @param {Number} startIndex (optional) The starting index (defaults to 0)
760 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
761 * @return {Ext.data.Record[]} An array of Records
763 getRange : function(start, end){
764 return this.data.getRange(start, end);
768 storeOptions : function(o){
769 o = Ext.apply({}, o);
772 this.lastOptions = o;
776 clearData: function(){
777 this.data.each(function(rec) {
783 <div id="method-Ext.data.Store-load"></div>/**
784 * <p>Loads the Record cache from the configured <tt>{@link #proxy}</tt> using the configured <tt>{@link #reader}</tt>.</p>
785 * <br><p>Notes:</p><div class="mdetail-params"><ul>
786 * <li><b><u>Important</u></b>: loading is asynchronous! This call will return before the new data has been
787 * loaded. To perform any post-processing where information from the load call is required, specify
788 * the <tt>callback</tt> function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.</li>
789 * <li>If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the <tt>start</tt> and <tt>limit</tt>
790 * properties in the <code>options.params</code> property to establish the initial position within the
791 * dataset, and the number of Records to cache on each read from the Proxy.</li>
792 * <li>If using {@link #remoteSort remote sorting}, the configured <code>{@link #sortInfo}</code>
793 * will be automatically included with the posted parameters according to the specified
794 * <code>{@link #paramNames}</code>.</li>
796 * @param {Object} options An object containing properties which control loading options:<ul>
797 * <li><b><tt>params</tt></b> :Object<div class="sub-desc"><p>An object containing properties to pass as HTTP
798 * parameters to a remote data source. <b>Note</b>: <code>params</code> will override any
799 * <code>{@link #baseParams}</code> of the same name.</p>
800 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
801 * <li><b>callback</b> : Function<div class="sub-desc"><p>A function to be called after the Records
802 * have been loaded. The callback is called after the load event is fired, and is passed the following arguments:<ul>
803 * <li>r : Ext.data.Record[] An Array of Records loaded.</li>
804 * <li>options : Options object from the load call.</li>
805 * <li>success : Boolean success indicator.</li></ul></p></div></li>
806 * <li><b>scope</b> : Object<div class="sub-desc"><p>Scope with which to call the callback (defaults
807 * to the Store object)</p></div></li>
808 * <li><b>add</b> : Boolean<div class="sub-desc"><p>Indicator to append loaded records rather than
809 * replace the current cache. <b>Note</b>: see note for <tt>{@link #loadData}</tt></p></div></li>
811 * @return {Boolean} If the <i>developer</i> provided <tt>{@link #beforeload}</tt> event handler returns
812 * <tt>false</tt>, the load call will abort and will return <tt>false</tt>; otherwise will return <tt>true</tt>.
814 load : function(options) {
815 options = options || {};
816 this.storeOptions(options);
817 if(this.sortInfo && this.remoteSort){
818 var pn = this.paramNames;
819 options.params = options.params || {};
820 options.params[pn.sort] = this.sortInfo.field;
821 options.params[pn.dir] = this.sortInfo.direction;
824 return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
826 this.handleException(e);
832 * updateRecord Should not be used directly. This method will be called automatically if a Writer is set.
833 * Listens to 'update' event.
834 * @param {Object} store
835 * @param {Object} record
836 * @param {Object} action
839 updateRecord : function(store, record, action) {
840 if (action == Ext.data.Record.EDIT && this.autoSave === true && (!record.phantom || (record.phantom && record.isValid()))) {
846 * Should not be used directly. Store#add will call this automatically if a Writer is set
847 * @param {Object} store
849 * @param {Object} index
852 createRecords : function(store, rs, index) {
853 for (var i = 0, len = rs.length; i < len; i++) {
854 if (rs[i].phantom && rs[i].isValid()) {
855 rs[i].markDirty(); // <-- Mark new records dirty
856 this.modified.push(rs[i]); // <-- add to modified
859 if (this.autoSave === true) {
865 * Destroys a record or records. Should not be used directly. It's called by Store#remove if a Writer is set.
866 * @param {Store} this
867 * @param {Ext.data.Record/Ext.data.Record[]}
868 * @param {Number} index
871 destroyRecord : function(store, record, index) {
872 if (this.modified.indexOf(record) != -1) { // <-- handled already if @cfg pruneModifiedRecords == true
873 this.modified.remove(record);
875 if (!record.phantom) {
876 this.removed.push(record);
878 // since the record has already been removed from the store but the server request has not yet been executed,
879 // must keep track of the last known index this record existed. If a server error occurs, the record can be
880 // put back into the store. @see Store#createCallback where the record is returned when response status === false
881 record.lastIndex = index;
883 if (this.autoSave === true) {
890 * This method should generally not be used directly. This method is called internally
891 * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
892 * {@link #remove}, or {@link #update} events fire.
893 * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
894 * @param {Record/Record[]} rs
895 * @param {Object} options
899 execute : function(action, rs, options, /* private */ batch) {
900 // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
901 if (!Ext.data.Api.isAction(action)) {
902 throw new Ext.data.Api.Error('execute', action);
904 // make sure options has a fresh, new params hash
905 options = Ext.applyIf(options||{}, {
908 if(batch !== undefined){
909 this.addToBatch(batch);
911 // have to separate before-events since load has a different signature than create,destroy and save events since load does not
912 // include the rs (record resultset) parameter. Capture return values from the beforeaction into doRequest flag.
913 var doRequest = true;
915 if (action === 'read') {
916 doRequest = this.fireEvent('beforeload', this, options);
917 Ext.applyIf(options.params, this.baseParams);
920 // if Writer is configured as listful, force single-record rs to be [{}] instead of {}
921 // TODO Move listful rendering into DataWriter where the @cfg is defined. Should be easy now.
922 if (this.writer.listful === true && this.restful !== true) {
923 rs = (Ext.isArray(rs)) ? rs : [rs];
925 // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
926 else if (Ext.isArray(rs) && rs.length == 1) {
929 // Write the action to options.params
930 if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
931 this.writer.apply(options.params, this.baseParams, action, rs);
934 if (doRequest !== false) {
935 // Send request to proxy.
936 if (this.writer && this.proxy.url && !this.proxy.restful && !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
937 options.params.xaction = action; // <-- really old, probaby unecessary.
939 // Note: Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions.
940 // We'll flip it now and send the value into DataProxy#request, since it's the value which maps to
941 // the user's configured DataProxy#api
942 // TODO Refactor all Proxies to accept an instance of Ext.data.Request (not yet defined) instead of this looooooong list
943 // of params. This method is an artifact from Ext2.
944 this.proxy.request(Ext.data.Api.actions[action], rs, options.params, this.reader, this.createCallback(action, rs, batch), this, options);
949 <div id="method-Ext.data.Store-save"></div>/**
950 * Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
951 * the configured <code>{@link #url}</code> will be used.
954 * --------------- --------------------
955 * removed records Ext.data.Api.actions.destroy
956 * phantom records Ext.data.Api.actions.create
957 * {@link #getModifiedRecords modified records} Ext.data.Api.actions.update
959 * @TODO: Create extensions of Error class and send associated Record with thrown exceptions.
960 * e.g.: Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
961 * @return {Number} batch Returns a number to uniquely identify the "batch" of saves occurring. -1 will be returned
962 * if there are no items to save or the save was cancelled.
966 throw new Ext.data.Store.Error('writer-undefined');
974 // DESTROY: First check for removed records. Records in this.removed are guaranteed non-phantoms. @see Store#remove
975 if(this.removed.length){
976 queue.push(['destroy', this.removed]);
979 // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
980 var rs = [].concat(this.getModifiedRecords());
982 // CREATE: Next check for phantoms within rs. splice-off and execute create.
984 for(var i = rs.length-1; i >= 0; i--){
985 if(rs[i].phantom === true){
986 var rec = rs.splice(i, 1).shift();
990 }else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
994 // If we have valid phantoms, create them...
996 queue.push(['create', phantoms]);
999 // UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
1001 queue.push(['update', rs]);
1006 batch = ++this.batchCounter;
1007 for(var i = 0; i < len; ++i){
1009 data[trans[0]] = trans[1];
1011 if(this.fireEvent('beforesave', this, data) !== false){
1012 for(var i = 0; i < len; ++i){
1014 this.doTransaction(trans[0], trans[1], batch);
1022 // private. Simply wraps call to Store#execute in try/catch. Defers to Store#handleException on error. Loops if batch: false
1023 doTransaction : function(action, rs, batch) {
1024 function transaction(records) {
1026 this.execute(action, records, undefined, batch);
1028 this.handleException(e);
1031 if(this.batch === false){
1032 for(var i = 0, len = rs.length; i < len; i++){
1033 transaction.call(this, rs[i]);
1036 transaction.call(this, rs);
1041 addToBatch : function(batch){
1042 var b = this.batches,
1043 key = this.batchKey + batch,
1056 removeFromBatch : function(batch, action, data){
1057 var b = this.batches,
1058 key = this.batchKey + batch,
1065 arr = o.data[action] || [];
1066 o.data[action] = arr.concat(data);
1070 this.fireEvent('save', this, batch, data);
1077 // @private callback-handler for remote CRUD actions
1078 // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
1079 createCallback : function(action, rs, batch) {
1080 var actions = Ext.data.Api.actions;
1081 return (action == 'read') ? this.loadRecords : function(data, response, success) {
1082 // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
1083 this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, [].concat(data));
1084 // If success === false here, exception will have been called in DataProxy
1085 if (success === true) {
1086 this.fireEvent('write', this, action, data, response, rs);
1088 this.removeFromBatch(batch, action, data);
1092 // Clears records from modified array after an exception event.
1093 // NOTE: records are left marked dirty. Do we want to commit them even though they were not updated/realized?
1094 // TODO remove this method?
1095 clearModified : function(rs) {
1096 if (Ext.isArray(rs)) {
1097 for (var n=rs.length-1;n>=0;n--) {
1098 this.modified.splice(this.modified.indexOf(rs[n]), 1);
1101 this.modified.splice(this.modified.indexOf(rs), 1);
1105 // remap record ids in MixedCollection after records have been realized. @see Store#onCreateRecords, @see DataReader#realize
1106 reMap : function(record) {
1107 if (Ext.isArray(record)) {
1108 for (var i = 0, len = record.length; i < len; i++) {
1109 this.reMap(record[i]);
1112 delete this.data.map[record._phid];
1113 this.data.map[record.id] = record;
1114 var index = this.data.keys.indexOf(record._phid);
1115 this.data.keys.splice(index, 1, record.id);
1116 delete record._phid;
1120 // @protected onCreateRecord proxy callback for create action
1121 onCreateRecords : function(success, rs, data) {
1122 if (success === true) {
1124 this.reader.realize(rs, data);
1128 this.handleException(e);
1129 if (Ext.isArray(rs)) {
1130 // Recurse to run back into the try {}. DataReader#realize splices-off the rs until empty.
1131 this.onCreateRecords(success, rs, data);
1137 // @protected, onUpdateRecords proxy callback for update action
1138 onUpdateRecords : function(success, rs, data) {
1139 if (success === true) {
1141 this.reader.update(rs, data);
1143 this.handleException(e);
1144 if (Ext.isArray(rs)) {
1145 // Recurse to run back into the try {}. DataReader#update splices-off the rs until empty.
1146 this.onUpdateRecords(success, rs, data);
1152 // @protected onDestroyRecords proxy callback for destroy action
1153 onDestroyRecords : function(success, rs, data) {
1154 // splice each rec out of this.removed
1155 rs = (rs instanceof Ext.data.Record) ? [rs] : [].concat(rs);
1156 for (var i=0,len=rs.length;i<len;i++) {
1157 this.removed.splice(this.removed.indexOf(rs[i]), 1);
1159 if (success === false) {
1160 // put records back into store if remote destroy fails.
1161 // @TODO: Might want to let developer decide.
1162 for (i=rs.length-1;i>=0;i--) {
1163 this.insert(rs[i].lastIndex, rs[i]); // <-- lastIndex set in Store#destroyRecord
1168 // protected handleException. Possibly temporary until Ext framework has an exception-handler.
1169 handleException : function(e) {
1170 // @see core/Error.js
1174 <div id="method-Ext.data.Store-reload"></div>/**
1175 * <p>Reloads the Record cache from the configured Proxy using the configured
1176 * {@link Ext.data.Reader Reader} and the options from the last load operation
1178 * <p><b>Note</b>: see the Important note in {@link #load}.</p>
1179 * @param {Object} options <p>(optional) An <tt>Object</tt> containing
1180 * {@link #load loading options} which may override the {@link #lastOptions options}
1181 * used in the last {@link #load} operation. See {@link #load} for details
1182 * (defaults to <tt>null</tt>, in which case the {@link #lastOptions} are
1184 * <br><p>To add new params to the existing params:</p><pre><code>
1185 lastOptions = myStore.lastOptions;
1186 Ext.apply(lastOptions.params, {
1189 myStore.reload(lastOptions);
1192 reload : function(options){
1193 this.load(Ext.applyIf(options||{}, this.lastOptions));
1197 // Called as a callback by the Reader during a load operation.
1198 loadRecords : function(o, options, success){
1199 if (this.isDestroyed === true) {
1202 if(!o || success === false){
1203 if(success !== false){
1204 this.fireEvent('load', this, [], options);
1206 if(options.callback){
1207 options.callback.call(options.scope || this, [], options, false, o);
1211 var r = o.records, t = o.totalRecords || r.length;
1212 if(!options || options.add !== true){
1213 if(this.pruneModifiedRecords){
1216 for(var i = 0, len = r.length; i < len; i++){
1220 this.data = this.snapshot;
1221 delete this.snapshot;
1224 this.data.addAll(r);
1225 this.totalLength = t;
1227 this.fireEvent('datachanged', this);
1229 this.totalLength = Math.max(t, this.data.length+r.length);
1232 this.fireEvent('load', this, r, options);
1233 if(options.callback){
1234 options.callback.call(options.scope || this, r, options, true);
1238 <div id="method-Ext.data.Store-loadData"></div>/**
1239 * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
1240 * which understands the format of the data must have been configured in the constructor.
1241 * @param {Object} data The data block from which to read the Records. The format of the data expected
1242 * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
1243 * that {@link Ext.data.Reader Reader}'s <tt>{@link Ext.data.Reader#readRecords}</tt> parameter.
1244 * @param {Boolean} append (Optional) <tt>true</tt> to append the new Records rather the default to replace
1245 * the existing cache.
1246 * <b>Note</b>: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
1247 * with ids which are already present in the Store will <i>replace</i> existing Records. Only Records with
1248 * new, unique ids will be added.
1250 loadData : function(o, append){
1251 var r = this.reader.readRecords(o);
1252 this.loadRecords(r, {add: append}, true);
1255 <div id="method-Ext.data.Store-getCount"></div>/**
1256 * Gets the number of cached records.
1257 * <p>If using paging, this may not be the total size of the dataset. If the data object
1258 * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
1259 * the dataset size. <b>Note</b>: see the Important note in {@link #load}.</p>
1260 * @return {Number} The number of Records in the Store's cache.
1262 getCount : function(){
1263 return this.data.length || 0;
1266 <div id="method-Ext.data.Store-getTotalCount"></div>/**
1267 * Gets the total number of records in the dataset as returned by the server.
1268 * <p>If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
1269 * must contain the dataset size. For remote data sources, the value for this property
1270 * (<tt>totalProperty</tt> for {@link Ext.data.JsonReader JsonReader},
1271 * <tt>totalRecords</tt> for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
1272 * <b>Note</b>: see the Important note in {@link #load}.</p>
1273 * @return {Number} The number of Records as specified in the data object passed to the Reader
1275 * <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
1277 getTotalCount : function(){
1278 return this.totalLength || 0;
1281 <div id="method-Ext.data.Store-getSortState"></div>/**
1282 * Returns an object describing the current sort state of this Store.
1283 * @return {Object} The sort state of the Store. An object with two properties:<ul>
1284 * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>
1285 * <li><b>direction : String<p class="sub-desc">The sort order, 'ASC' or 'DESC' (case-sensitive).</p></li>
1287 * See <tt>{@link #sortInfo}</tt> for additional details.
1289 getSortState : function(){
1290 return this.sortInfo;
1294 applySort : function(){
1295 if(this.sortInfo && !this.remoteSort){
1296 var s = this.sortInfo, f = s.field;
1297 this.sortData(f, s.direction);
1302 sortData : function(f, direction){
1303 direction = direction || 'ASC';
1304 var st = this.fields.get(f).sortType;
1305 var fn = function(r1, r2){
1306 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
1307 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
1309 this.data.sort(direction, fn);
1310 if(this.snapshot && this.snapshot != this.data){
1311 this.snapshot.sort(direction, fn);
1315 <div id="method-Ext.data.Store-setDefaultSort"></div>/**
1316 * Sets the default sort column and order to be used by the next {@link #load} operation.
1317 * @param {String} fieldName The name of the field to sort by.
1318 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1320 setDefaultSort : function(field, dir){
1321 dir = dir ? dir.toUpperCase() : 'ASC';
1322 this.sortInfo = {field: field, direction: dir};
1323 this.sortToggle[field] = dir;
1326 <div id="method-Ext.data.Store-sort"></div>/**
1328 * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
1329 * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
1330 * @param {String} fieldName The name of the field to sort by.
1331 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1333 sort : function(fieldName, dir){
1334 var f = this.fields.get(fieldName);
1339 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
1340 dir = (this.sortToggle[f.name] || 'ASC').toggle('ASC', 'DESC');
1345 var st = (this.sortToggle) ? this.sortToggle[f.name] : null;
1346 var si = (this.sortInfo) ? this.sortInfo : null;
1348 this.sortToggle[f.name] = dir;
1349 this.sortInfo = {field: f.name, direction: dir};
1350 if(!this.remoteSort){
1352 this.fireEvent('datachanged', this);
1354 if (!this.load(this.lastOptions)) {
1356 this.sortToggle[f.name] = st;
1365 <div id="method-Ext.data.Store-each"></div>/**
1366 * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
1367 * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
1368 * Returning <tt>false</tt> aborts and exits the iteration.
1369 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed.
1370 * Defaults to the current {@link Ext.data.Record Record} in the iteration.
1372 each : function(fn, scope){
1373 this.data.each(fn, scope);
1376 <div id="method-Ext.data.Store-getModifiedRecords"></div>/**
1377 * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are
1378 * persisted across load operations (e.g., during paging). <b>Note</b>: deleted records are not
1379 * included. See also <tt>{@link #pruneModifiedRecords}</tt> and
1380 * {@link Ext.data.Record}<tt>{@link Ext.data.Record#markDirty markDirty}.</tt>.
1381 * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
1382 * modifications. To obtain modified fields within a modified record see
1383 *{@link Ext.data.Record}<tt>{@link Ext.data.Record#modified modified}.</tt>.
1385 getModifiedRecords : function(){
1386 return this.modified;
1390 createFilterFn : function(property, value, anyMatch, caseSensitive){
1391 if(Ext.isEmpty(value, false)){
1394 value = this.data.createValueMatcher(value, anyMatch, caseSensitive);
1396 return value.test(r.data[property]);
1400 <div id="method-Ext.data.Store-sum"></div>/**
1401 * Sums the value of <tt>property</tt> for each {@link Ext.data.Record record} between <tt>start</tt>
1402 * and <tt>end</tt> and returns the result.
1403 * @param {String} property A field in each record
1404 * @param {Number} start (optional) The record index to start at (defaults to <tt>0</tt>)
1405 * @param {Number} end (optional) The last record index to include (defaults to length - 1)
1406 * @return {Number} The sum
1408 sum : function(property, start, end){
1409 var rs = this.data.items, v = 0;
1411 end = (end || end === 0) ? end : rs.length-1;
1413 for(var i = start; i <= end; i++){
1414 v += (rs[i].data[property] || 0);
1419 <div id="method-Ext.data.Store-filter"></div>/**
1420 * Filter the {@link Ext.data.Record records} by a specified property.
1421 * @param {String} field A field on your records
1422 * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
1423 * against the field.
1424 * @param {Boolean} anyMatch (optional) <tt>true</tt> to match any part not just the beginning
1425 * @param {Boolean} caseSensitive (optional) <tt>true</tt> for case sensitive comparison
1427 filter : function(property, value, anyMatch, caseSensitive){
1428 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1429 return fn ? this.filterBy(fn) : this.clearFilter();
1432 <div id="method-Ext.data.Store-filterBy"></div>/**
1433 * Filter by a function. The specified function will be called for each
1434 * Record in this Store. If the function returns <tt>true</tt> the Record is included,
1435 * otherwise it is filtered out.
1436 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1437 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1438 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1439 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1441 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1443 filterBy : function(fn, scope){
1444 this.snapshot = this.snapshot || this.data;
1445 this.data = this.queryBy(fn, scope||this);
1446 this.fireEvent('datachanged', this);
1449 <div id="method-Ext.data.Store-query"></div>/**
1450 * Query the records by a specified property.
1451 * @param {String} field A field on your records
1452 * @param {String/RegExp} value Either a string that the field
1453 * should begin with, or a RegExp to test against the field.
1454 * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
1455 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1456 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1458 query : function(property, value, anyMatch, caseSensitive){
1459 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1460 return fn ? this.queryBy(fn) : this.data.clone();
1463 <div id="method-Ext.data.Store-queryBy"></div>/**
1464 * Query the cached records in this Store using a filtering function. The specified function
1465 * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
1466 * included in the results.
1467 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1468 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1469 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1470 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1472 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1473 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1475 queryBy : function(fn, scope){
1476 var data = this.snapshot || this.data;
1477 return data.filterBy(fn, scope||this);
1480 <div id="method-Ext.data.Store-find"></div>/**
1481 * Finds the index of the first matching Record in this store by a specific field value.
1482 * @param {String} fieldName The name of the Record field to test.
1483 * @param {String/RegExp} value Either a string that the field value
1484 * should begin with, or a RegExp to test against the field.
1485 * @param {Number} startIndex (optional) The index to start searching at
1486 * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1487 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1488 * @return {Number} The matched index or -1
1490 find : function(property, value, start, anyMatch, caseSensitive){
1491 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1492 return fn ? this.data.findIndexBy(fn, null, start) : -1;
1495 <div id="method-Ext.data.Store-findExact"></div>/**
1496 * Finds the index of the first matching Record in this store by a specific field value.
1497 * @param {String} fieldName The name of the Record field to test.
1498 * @param {Mixed} value The value to match the field against.
1499 * @param {Number} startIndex (optional) The index to start searching at
1500 * @return {Number} The matched index or -1
1502 findExact: function(property, value, start){
1503 return this.data.findIndexBy(function(rec){
1504 return rec.get(property) === value;
1508 <div id="method-Ext.data.Store-findBy"></div>/**
1509 * Find the index of the first matching Record in this Store by a function.
1510 * If the function returns <tt>true</tt> it is considered a match.
1511 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1512 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1513 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1514 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1516 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1517 * @param {Number} startIndex (optional) The index to start searching at
1518 * @return {Number} The matched index or -1
1520 findBy : function(fn, scope, start){
1521 return this.data.findIndexBy(fn, scope, start);
1524 <div id="method-Ext.data.Store-collect"></div>/**
1525 * Collects unique values for a particular dataIndex from this store.
1526 * @param {String} dataIndex The property to collect
1527 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
1528 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
1529 * @return {Array} An array of the unique values
1531 collect : function(dataIndex, allowNull, bypassFilter){
1532 var d = (bypassFilter === true && this.snapshot) ?
1533 this.snapshot.items : this.data.items;
1534 var v, sv, r = [], l = {};
1535 for(var i = 0, len = d.length; i < len; i++){
1536 v = d[i].data[dataIndex];
1538 if((allowNull || !Ext.isEmpty(v)) && !l[sv]){
1546 <div id="method-Ext.data.Store-clearFilter"></div>/**
1547 * Revert to a view of the Record cache with no filtering applied.
1548 * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
1549 * {@link #datachanged} event.
1551 clearFilter : function(suppressEvent){
1552 if(this.isFiltered()){
1553 this.data = this.snapshot;
1554 delete this.snapshot;
1555 if(suppressEvent !== true){
1556 this.fireEvent('datachanged', this);
1561 <div id="method-Ext.data.Store-isFiltered"></div>/**
1562 * Returns true if this store is currently filtered
1565 isFiltered : function(){
1566 return this.snapshot && this.snapshot != this.data;
1570 afterEdit : function(record){
1571 if(this.modified.indexOf(record) == -1){
1572 this.modified.push(record);
1574 this.fireEvent('update', this, record, Ext.data.Record.EDIT);
1578 afterReject : function(record){
1579 this.modified.remove(record);
1580 this.fireEvent('update', this, record, Ext.data.Record.REJECT);
1584 afterCommit : function(record){
1585 this.modified.remove(record);
1586 this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
1589 <div id="method-Ext.data.Store-commitChanges"></div>/**
1590 * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
1591 * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
1592 * Ext.data.Record.COMMIT.
1594 commitChanges : function(){
1595 var m = this.modified.slice(0);
1597 for(var i = 0, len = m.length; i < len; i++){
1602 <div id="method-Ext.data.Store-rejectChanges"></div>/**
1603 * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
1605 rejectChanges : function(){
1606 var m = this.modified.slice(0);
1608 for(var i = 0, len = m.length; i < len; i++){
1611 var m = this.removed.slice(0).reverse();
1613 for(var i = 0, len = m.length; i < len; i++){
1614 this.insert(m[i].lastIndex||0, m[i]);
1620 onMetaChange : function(meta){
1621 this.recordType = this.reader.recordType;
1622 this.fields = this.recordType.prototype.fields;
1623 delete this.snapshot;
1624 if(this.reader.meta.sortInfo){
1625 this.sortInfo = this.reader.meta.sortInfo;
1626 }else if(this.sortInfo && !this.fields.get(this.sortInfo.field)){
1627 delete this.sortInfo;
1630 this.writer.meta = this.reader.meta;
1633 this.fireEvent('metachange', this, this.reader.meta);
1637 findInsertIndex : function(record){
1638 this.suspendEvents();
1639 var data = this.data.clone();
1640 this.data.add(record);
1642 var index = this.data.indexOf(record);
1644 this.resumeEvents();
1648 <div id="method-Ext.data.Store-setBaseParam"></div>/**
1649 * Set the value for a property name in this store's {@link #baseParams}. Usage:</p><pre><code>
1650 myStore.setBaseParam('foo', {bar:3});
1652 * @param {String} name Name of the property to assign
1653 * @param {Mixed} value Value to assign the <tt>name</tt>d property
1655 setBaseParam : function (name, value){
1656 this.baseParams = this.baseParams || {};
1657 this.baseParams[name] = value;
1661 Ext.reg('store', Ext.data.Store);
1663 <div id="cls-Ext.data.Store.Error"></div>/**
1664 * @class Ext.data.Store.Error
1665 * @extends Ext.Error
1666 * Store Error extension.
1667 * @param {String} name
1669 Ext.data.Store.Error = Ext.extend(Ext.Error, {
1670 name: 'Ext.data.Store'
1672 Ext.apply(Ext.data.Store.Error.prototype, {
1674 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'