3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.data.Store"></div>/**
9 * @class Ext.data.Store
10 * @extends Ext.util.Observable
11 * <p>The Store class encapsulates a client side cache of {@link Ext.data.Record Record}
12 * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},
13 * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.</p>
14 * <p><u>Retrieving Data</u></p>
15 * <p>A Store object may access a data object using:<div class="mdetail-params"><ul>
16 * <li>{@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}</li>
17 * <li>{@link #data} to automatically pass in data</li>
18 * <li>{@link #loadData} to manually pass in data</li>
20 * <p><u>Reading Data</u></p>
21 * <p>A Store object has no inherent knowledge of the format of the data object (it could be
22 * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation}
23 * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data
25 * <p><u>Store Types</u></p>
26 * <p>There are several implementations of Store available which are customized for use with
27 * a specific DataReader implementation. Here is an example using an ArrayStore which implicitly
28 * creates a reader commensurate to an Array data object.</p>
30 var myStore = new Ext.data.ArrayStore({
31 fields: ['fullname', 'first'],
32 idIndex: 0 // id for each record will be the first element
35 * <p>For custom implementations create a basic {@link Ext.data.Store} configured as needed:</p>
37 // create a {@link Ext.data.Record Record} constructor:
38 var rt = Ext.data.Record.create([
42 var myStore = new Ext.data.Store({
43 // explicitly create reader
44 reader: new Ext.data.ArrayReader(
46 idIndex: 0 // id for each record will be the first element
52 * <p>Load some data into store (note the data object is an array which corresponds to the reader):</p>
55 [1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
56 [2, 'Barney Rubble', 'Barney']
58 myStore.loadData(myData);
60 * <p>Records are cached and made available through accessor functions. An example of adding
61 * a record to the store:</p>
64 fullname: 'Full Name',
67 var recId = 100; // provide unique id for the record
68 var r = new myStore.recordType(defaultData, ++recId); // create new record
69 myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add})
72 * Creates a new Store.
73 * @param {Object} config A config object containing the objects needed for the Store to access data,
74 * and read the data into Records.
77 Ext.data.Store = function(config){
78 this.data = new Ext.util.MixedCollection(false);
79 this.data.getKey = function(o){
82 <div id="prop-Ext.data.Store-baseParams"></div>/**
83 * See the <code>{@link #baseParams corresponding configuration option}</code>
84 * for a description of this property.
85 * To modify this property see <code>{@link #setBaseParam}</code>.
90 // temporary removed-records cache
93 if(config && config.data){
94 this.inlineData = config.data;
98 Ext.apply(this, config);
100 this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
102 if(this.url && !this.proxy){
103 this.proxy = new Ext.data.HttpProxy({url: this.url});
105 // If Store is RESTful, so too is the DataProxy
106 if (this.restful === true && this.proxy) {
107 // When operating RESTfully, a unique transaction is generated for each record.
109 Ext.data.Api.restify(this.proxy);
112 if(this.reader){ // reader passed
113 if(!this.recordType){
114 this.recordType = this.reader.recordType;
116 if(this.reader.onMetaChange){
117 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
119 if (this.writer) { // writer passed
120 this.writer.meta = this.reader.meta;
121 this.pruneModifiedRecords = true;
125 <div id="prop-Ext.data.Store-recordType"></div>/**
126 * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
127 * {@link Ext.data.DataReader Reader}. Read-only.
128 * <p>If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
129 * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
130 * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).</p>
131 * <p>This property may be used to create new Records of the type held in this Store, for example:</p><pre><code>
132 // create the data store
133 var store = new Ext.data.ArrayStore({
137 {name: 'price', type: 'float'},
138 {name: 'change', type: 'float'},
139 {name: 'pctChange', type: 'float'},
140 {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
143 store.loadData(myData);
146 var grid = new Ext.grid.EditorGridPanel({
148 colModel: new Ext.grid.ColumnModel({
150 {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
151 {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
152 {header: 'Change', renderer: change, dataIndex: 'change'},
153 {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
154 {header: 'Last Updated', width: 85,
155 renderer: Ext.util.Format.dateRenderer('m/d/Y'),
156 dataIndex: 'lastChange'}
163 autoExpandColumn: 'company', // match the id specified in the column model
169 handler : function(){
172 company: 'New Company',
173 lastChange: (new Date()).clearTime(),
177 var recId = 3; // provide unique id
178 var p = new store.recordType(defaultData, recId); // create new record
180 store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
181 grid.startEditing(0, 0);
186 * @property recordType
191 <div id="prop-Ext.data.Store-fields"></div>/**
192 * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
193 * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
195 * @type Ext.util.MixedCollection
197 this.fields = this.recordType.prototype.fields;
202 <div id="event-Ext.data.Store-datachanged"></div>/**
204 * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
205 * widget that is using this Store as a Record cache should refresh its view.
206 * @param {Store} this
209 <div id="event-Ext.data.Store-metachange"></div>/**
211 * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
212 * @param {Store} this
213 * @param {Object} meta The JSON metadata
216 <div id="event-Ext.data.Store-add"></div>/**
218 * Fires when Records have been {@link #add}ed to the Store
219 * @param {Store} this
220 * @param {Ext.data.Record[]} records The array of Records added
221 * @param {Number} index The index at which the record(s) were added
224 <div id="event-Ext.data.Store-remove"></div>/**
226 * Fires when a Record has been {@link #remove}d from the Store
227 * @param {Store} this
228 * @param {Ext.data.Record} record The Record that was removed
229 * @param {Number} index The index at which the record was removed
232 <div id="event-Ext.data.Store-update"></div>/**
234 * Fires when a Record has been updated
235 * @param {Store} this
236 * @param {Ext.data.Record} record The Record that was updated
237 * @param {String} operation The update operation being performed. Value may be one of:
240 Ext.data.Record.REJECT
241 Ext.data.Record.COMMIT
245 <div id="event-Ext.data.Store-clear"></div>/**
247 * Fires when the data cache has been cleared.
248 * @param {Store} this
251 <div id="event-Ext.data.Store-exception"></div>/**
253 * <p>Fires if an exception occurs in the Proxy during a remote request.
254 * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
255 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
256 * for additional details.
257 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
261 <div id="event-Ext.data.Store-beforeload"></div>/**
263 * Fires before a request is made for a new data object. If the beforeload handler returns
264 * <tt>false</tt> the {@link #load} action will be canceled.
265 * @param {Store} this
266 * @param {Object} options The loading options that were specified (see {@link #load} for details)
269 <div id="event-Ext.data.Store-load"></div>/**
271 * Fires after a new set of Records has been loaded.
272 * @param {Store} this
273 * @param {Ext.data.Record[]} records The Records that were loaded
274 * @param {Object} options The loading options that were specified (see {@link #load} for details)
277 <div id="event-Ext.data.Store-loadexception"></div>/**
278 * @event loadexception
279 * <p>This event is <b>deprecated</b> in favor of the catch-all <b><code>{@link #exception}</code></b>
281 * <p>This event is relayed through the corresponding {@link Ext.data.DataProxy}.
282 * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
283 * for additional details.
284 * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
288 <div id="event-Ext.data.Store-beforewrite"></div>/**
290 * @param {DataProxy} this
291 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
292 * @param {Record/Array[Record]} rs
293 * @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)
294 * @param {Object} arg The callback's arg object passed to the {@link #request} function
297 <div id="event-Ext.data.Store-write"></div>/**
299 * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
300 * Success or failure of the action is available in the <code>result['successProperty']</code> property.
301 * The server-code might set the <code>successProperty</code> to <tt>false</tt> if a database validation
302 * failed, for example.
303 * @param {Ext.data.Store} store
304 * @param {String} action [Ext.data.Api.actions.create|update|destroy]
305 * @param {Object} result The 'data' picked-out out of the response for convenience.
306 * @param {Ext.Direct.Transaction} res
307 * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
313 this.relayEvents(this.proxy, ['loadexception', 'exception']);
315 // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
319 add: this.createRecords,
320 remove: this.destroyRecord,
321 update: this.updateRecord
325 this.sortToggle = {};
327 this.setDefaultSort(this.sortField, this.sortDir);
328 }else if(this.sortInfo){
329 this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
332 Ext.data.Store.superclass.constructor.call(this);
335 this.storeId = this.id;
339 Ext.StoreMgr.register(this);
342 this.loadData(this.inlineData);
343 delete this.inlineData;
344 }else if(this.autoLoad){
345 this.load.defer(10, this, [
346 typeof this.autoLoad == 'object' ?
347 this.autoLoad : undefined]);
350 Ext.extend(Ext.data.Store, Ext.util.Observable, {
351 <div id="cfg-Ext.data.Store-storeId"></div>/**
352 * @cfg {String} storeId If passed, the id to use to register with the <b>{@link Ext.StoreMgr StoreMgr}</b>.
353 * <p><b>Note</b>: if a (deprecated) <tt>{@link #id}</tt> is specified it will supersede the <tt>storeId</tt>
356 <div id="cfg-Ext.data.Store-url"></div>/**
357 * @cfg {String} url If a <tt>{@link #proxy}</tt> is not specified the <tt>url</tt> will be used to
358 * implicitly configure a {@link Ext.data.HttpProxy HttpProxy} if an <tt>url</tt> is specified.
359 * Typically this option, or the <code>{@link #data}</code> option will be specified.
361 <div id="cfg-Ext.data.Store-autoLoad"></div>/**
362 * @cfg {Boolean/Object} autoLoad If <tt>{@link #data}</tt> is not specified, and if <tt>autoLoad</tt>
363 * is <tt>true</tt> or an <tt>Object</tt>, this store's {@link #load} method is automatically called
364 * after creation. If the value of <tt>autoLoad</tt> is an <tt>Object</tt>, this <tt>Object</tt> will
365 * be passed to the store's {@link #load} method.
367 <div id="cfg-Ext.data.Store-proxy"></div>/**
368 * @cfg {Ext.data.DataProxy} proxy The {@link Ext.data.DataProxy DataProxy} object which provides
369 * access to a data object. See <code>{@link #url}</code>.
371 <div id="cfg-Ext.data.Store-data"></div>/**
372 * @cfg {Array} data An inline data object readable by the <code>{@link #reader}</code>.
373 * Typically this option, or the <code>{@link #url}</code> option will be specified.
375 <div id="cfg-Ext.data.Store-reader"></div>/**
376 * @cfg {Ext.data.DataReader} reader The {@link Ext.data.DataReader Reader} object which processes the
377 * data object and returns an Array of {@link Ext.data.Record} objects which are cached keyed by their
378 * <b><tt>{@link Ext.data.Record#id id}</tt></b> property.
380 <div id="cfg-Ext.data.Store-writer"></div>/**
381 * @cfg {Ext.data.DataWriter} writer
382 * <p>The {@link Ext.data.DataWriter Writer} object which processes a record object for being written
383 * to the server-side database.</p>
384 * <br><p>When a writer is installed into a Store the {@link #add}, {@link #remove}, and {@link #update}
385 * events on the store are monitored in order to remotely {@link #createRecords create records},
386 * {@link #destroyRecord destroy records}, or {@link #updateRecord update records}.</p>
387 * <br><p>The proxy for this store will relay any {@link #writexception} events to this store.</p>
388 * <br><p>Sample implementation:
390 var writer = new {@link Ext.data.JsonWriter}({
392 writeAllFields: true // write all fields, not just those that changed
395 // Typical Store collecting the Proxy, Reader and Writer together.
396 var store = new Ext.data.Store({
401 writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
403 autoSave: false // <-- false to delay executing create, update, destroy requests
404 // until specifically told to do so.
409 <div id="cfg-Ext.data.Store-baseParams"></div>/**
410 * @cfg {Object} baseParams
411 * <p>An object containing properties which are to be sent as parameters
412 * for <i>every</i> HTTP request.</p>
413 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
414 * <p><b>Note</b>: <code>baseParams</code> may be superseded by any <code>params</code>
415 * specified in a <code>{@link #load}</code> request, see <code>{@link #load}</code>
416 * for more details.</p>
417 * This property may be modified after creation using the <code>{@link #setBaseParam}</code>
421 <div id="cfg-Ext.data.Store-sortInfo"></div>/**
422 * @cfg {Object} sortInfo A config object to specify the sort order in the request of a Store's
423 * {@link #load} operation. Note that for local sorting, the <tt>direction</tt> property is
424 * case-sensitive. See also {@link #remoteSort} and {@link #paramNames}.
425 * For example:<pre><code>
428 direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
432 <div id="cfg-Ext.data.Store-remoteSort"></div>/**
433 * @cfg {boolean} remoteSort <tt>true</tt> if sorting is to be handled by requesting the <tt>{@link #proxy Proxy}</tt>
434 * to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
435 * in place (defaults to <tt>false</tt>).
436 * <p>If <tt>remoteSort</tt> is <tt>true</tt>, then clicking on a {@link Ext.grid.Column Grid Column}'s
437 * {@link Ext.grid.Column#header header} causes the current page to be requested from the server appending
438 * the following two parameters to the <b><tt>{@link #load params}</tt></b>:<div class="mdetail-params"><ul>
439 * <li><b><tt>sort</tt></b> : String<p class="sub-desc">The <tt>name</tt> (as specified in the Record's
440 * {@link Ext.data.Field Field definition}) of the field to sort on.</p></li>
441 * <li><b><tt>dir</tt></b> : String<p class="sub-desc">The direction of the sort, 'ASC' or 'DESC' (case-sensitive).</p></li>
446 <div id="cfg-Ext.data.Store-autoDestroy"></div>/**
447 * @cfg {Boolean} autoDestroy <tt>true</tt> to destroy the store when the component the store is bound
448 * to is destroyed (defaults to <tt>false</tt>).
449 * <p><b>Note</b>: this should be set to true when using stores that are bound to only 1 component.</p>
453 <div id="cfg-Ext.data.Store-pruneModifiedRecords"></div>/**
454 * @cfg {Boolean} pruneModifiedRecords <tt>true</tt> to clear all modified record information each time
455 * the store is loaded or when a record is removed (defaults to <tt>false</tt>). See {@link #getModifiedRecords}
456 * for the accessor method to retrieve the modified records.
458 pruneModifiedRecords : false,
460 <div id="prop-Ext.data.Store-lastOptions"></div>/**
461 * Contains the last options object used as the parameter to the {@link #load} method. See {@link #load}
462 * for the details of what this may contain. This may be useful for accessing any params which were used
463 * to load the current Record cache.
468 <div id="cfg-Ext.data.Store-autoSave"></div>/**
469 * @cfg {Boolean} autoSave
470 * <p>Defaults to <tt>true</tt> causing the store to automatically {@link #save} records to
471 * the server when a record is modified (ie: becomes 'dirty'). Specify <tt>false</tt> to manually call {@link #save}
472 * to send all modifiedRecords to the server.</p>
473 * <br><p><b>Note</b>: each CRUD action will be sent as a separate request.</p>
477 <div id="cfg-Ext.data.Store-batch"></div>/**
478 * @cfg {Boolean} batch
479 * <p>Defaults to <tt>true</tt> (unless <code>{@link #restful}:true</code>). Multiple
480 * requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) will be combined
481 * and sent as one transaction. Only applies when <code>{@link #autoSave}</code> is set
482 * to <tt>false</tt>.</p>
483 * <br><p>If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is
484 * generated for each record.</p>
488 <div id="cfg-Ext.data.Store-restful"></div>/**
489 * @cfg {Boolean} restful
490 * Defaults to <tt>false</tt>. Set to <tt>true</tt> to have the Store and the set
491 * Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
492 * PUT and DELETE requests to the server. The HTTP method used for any given CRUD
493 * action is described in {@link Ext.data.Api#restActions}. For additional information
494 * see {@link Ext.data.DataProxy#restful}.
495 * <p><b>Note</b>: if <code>{@link #restful}:true</code> <code>batch</code> will
496 * internally be set to <tt>false</tt>.</p>
500 <div id="cfg-Ext.data.Store-paramNames"></div>/**
501 * @cfg {Object} paramNames
502 * <p>An object containing properties which specify the names of the paging and
503 * sorting parameters passed to remote servers when loading blocks of data. By default, this
504 * object takes the following form:</p><pre><code>
506 start : 'start', // The parameter name which specifies the start row
507 limit : 'limit', // The parameter name which specifies number of rows to return
508 sort : 'sort', // The parameter name which specifies the column to sort on
509 dir : 'dir' // The parameter name which specifies the sort direction
512 * <p>The server must produce the requested data block upon receipt of these parameter names.
513 * If different parameter names are required, this property can be overriden using a configuration
515 * <p>A {@link Ext.PagingToolbar PagingToolbar} bound to this Store uses this property to determine
516 * the parameter names to use in its {@link #load requests}.
518 paramNames : undefined,
520 <div id="cfg-Ext.data.Store-defaultParamNames"></div>/**
521 * @cfg {Object} defaultParamNames
522 * Provides the default values for the {@link #paramNames} property. To globally modify the parameters
523 * for all stores, this object should be changed on the store prototype.
525 defaultParamNames : {
532 <div id="method-Ext.data.Store-destroy"></div>/**
533 * Destroys the store.
535 destroy : function(){
537 Ext.StoreMgr.unregister(this);
540 Ext.destroy(this.proxy);
541 this.reader = this.writer = null;
542 this.purgeListeners();
545 <div id="method-Ext.data.Store-add"></div>/**
546 * Add Records to the Store and fires the {@link #add} event. To add Records
547 * to the store from a remote source use <code>{@link #load}({add:true})</code>.
548 * See also <code>{@link #recordType}</code> and <code>{@link #insert}</code>.
549 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
550 * to add to the cache. See {@link #recordType}.
552 add : function(records){
553 records = [].concat(records);
554 if(records.length < 1){
557 for(var i = 0, len = records.length; i < len; i++){
558 records[i].join(this);
560 var index = this.data.length;
561 this.data.addAll(records);
563 this.snapshot.addAll(records);
565 this.fireEvent('add', this, records, index);
568 <div id="method-Ext.data.Store-addSorted"></div>/**
569 * (Local sort only) Inserts the passed Record into the Store at the index where it
570 * should go based on the current sort information.
571 * @param {Ext.data.Record} record
573 addSorted : function(record){
574 var index = this.findInsertIndex(record);
575 this.insert(index, record);
578 <div id="method-Ext.data.Store-remove"></div>/**
579 * Remove a Record from the Store and fires the {@link #remove} event.
580 * @param {Ext.data.Record} record The Ext.data.Record object to remove from the cache.
582 remove : function(record){
583 var index = this.data.indexOf(record);
585 this.data.removeAt(index);
586 if(this.pruneModifiedRecords){
587 this.modified.remove(record);
590 this.snapshot.remove(record);
592 this.fireEvent('remove', this, record, index);
596 <div id="method-Ext.data.Store-removeAt"></div>/**
597 * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
598 * @param {Number} index The index of the record to remove.
600 removeAt : function(index){
601 this.remove(this.getAt(index));
604 <div id="method-Ext.data.Store-removeAll"></div>/**
605 * Remove all Records from the Store and fires the {@link #clear} event.
607 removeAll : function(){
610 this.snapshot.clear();
612 if(this.pruneModifiedRecords){
615 this.fireEvent('clear', this);
618 <div id="method-Ext.data.Store-insert"></div>/**
619 * Inserts Records into the Store at the given index and fires the {@link #add} event.
620 * See also <code>{@link #add}</code> and <code>{@link #addSorted}</code>.
621 * @param {Number} index The start index at which to insert the passed Records.
622 * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
624 insert : function(index, records){
625 records = [].concat(records);
626 for(var i = 0, len = records.length; i < len; i++){
627 this.data.insert(index, records[i]);
628 records[i].join(this);
630 this.fireEvent('add', this, records, index);
633 <div id="method-Ext.data.Store-indexOf"></div>/**
634 * Get the index within the cache of the passed Record.
635 * @param {Ext.data.Record} record The Ext.data.Record object to find.
636 * @return {Number} The index of the passed Record. Returns -1 if not found.
638 indexOf : function(record){
639 return this.data.indexOf(record);
642 <div id="method-Ext.data.Store-indexOfId"></div>/**
643 * Get the index within the cache of the Record with the passed id.
644 * @param {String} id The id of the Record to find.
645 * @return {Number} The index of the Record. Returns -1 if not found.
647 indexOfId : function(id){
648 return this.data.indexOfKey(id);
651 <div id="method-Ext.data.Store-getById"></div>/**
652 * Get the Record with the specified id.
653 * @param {String} id The id of the Record to find.
654 * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
656 getById : function(id){
657 return this.data.key(id);
660 <div id="method-Ext.data.Store-getAt"></div>/**
661 * Get the Record at the specified index.
662 * @param {Number} index The index of the Record to find.
663 * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
665 getAt : function(index){
666 return this.data.itemAt(index);
669 <div id="method-Ext.data.Store-getRange"></div>/**
670 * Returns a range of Records between specified indices.
671 * @param {Number} startIndex (optional) The starting index (defaults to 0)
672 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
673 * @return {Ext.data.Record[]} An array of Records
675 getRange : function(start, end){
676 return this.data.getRange(start, end);
680 storeOptions : function(o){
681 o = Ext.apply({}, o);
684 this.lastOptions = o;
687 <div id="method-Ext.data.Store-load"></div>/**
688 * <p>Loads the Record cache from the configured <tt>{@link #proxy}</tt> using the configured <tt>{@link #reader}</tt>.</p>
689 * <br><p>Notes:</p><div class="mdetail-params"><ul>
690 * <li><b><u>Important</u></b>: loading is asynchronous! This call will return before the new data has been
691 * loaded. To perform any post-processing where information from the load call is required, specify
692 * the <tt>callback</tt> function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.</li>
693 * <li>If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the <tt>start</tt> and <tt>limit</tt>
694 * properties in the <code>options.params</code> property to establish the initial position within the
695 * dataset, and the number of Records to cache on each read from the Proxy.</li>
696 * <li>If using {@link #remoteSort remote sorting}, the configured <code>{@link #sortInfo}</code>
697 * will be automatically included with the posted parameters according to the specified
698 * <code>{@link #paramNames}</code>.</li>
700 * @param {Object} options An object containing properties which control loading options:<ul>
701 * <li><b><tt>params</tt></b> :Object<div class="sub-desc"><p>An object containing properties to pass as HTTP
702 * parameters to a remote data source. <b>Note</b>: <code>params</code> will override any
703 * <code>{@link #baseParams}</code> of the same name.</p>
704 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
705 * <li><b><tt>callback</tt></b> : Function<div class="sub-desc"><p>A function to be called after the Records
706 * have been loaded. The <tt>callback</tt> is called after the load event and is passed the following arguments:<ul>
707 * <li><tt>r</tt> : Ext.data.Record[]</li>
708 * <li><tt>options</tt>: Options object from the load call</li>
709 * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div></li>
710 * <li><b><tt>scope</tt></b> : Object<div class="sub-desc"><p>Scope with which to call the callback (defaults
711 * to the Store object)</p></div></li>
712 * <li><b><tt>add</tt></b> : Boolean<div class="sub-desc"><p>Indicator to append loaded records rather than
713 * replace the current cache. <b>Note</b>: see note for <tt>{@link #loadData}</tt></p></div></li>
715 * @return {Boolean} If the <i>developer</i> provided <tt>{@link #beforeload}</tt> event handler returns
716 * <tt>false</tt>, the load call will abort and will return <tt>false</tt>; otherwise will return <tt>true</tt>.
718 load : function(options) {
719 options = options || {};
720 this.storeOptions(options);
721 if(this.sortInfo && this.remoteSort){
722 var pn = this.paramNames;
723 options.params = options.params || {};
724 options.params[pn.sort] = this.sortInfo.field;
725 options.params[pn.dir] = this.sortInfo.direction;
728 return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
730 this.handleException(e);
736 * updateRecord Should not be used directly. This method will be called automatically if a Writer is set.
737 * Listens to 'update' event.
738 * @param {Object} store
739 * @param {Object} record
740 * @param {Object} action
743 updateRecord : function(store, record, action) {
744 if (action == Ext.data.Record.EDIT && this.autoSave === true && (!record.phantom || (record.phantom && record.isValid))) {
750 * Should not be used directly. Store#add will call this automatically if a Writer is set
751 * @param {Object} store
753 * @param {Object} index
756 createRecords : function(store, rs, index) {
757 for (var i = 0, len = rs.length; i < len; i++) {
758 if (rs[i].phantom && rs[i].isValid()) {
759 rs[i].markDirty(); // <-- Mark new records dirty
760 this.modified.push(rs[i]); // <-- add to modified
763 if (this.autoSave === true) {
769 * Destroys a record or records. Should not be used directly. It's called by Store#remove if a Writer is set.
770 * @param {Store} this
771 * @param {Ext.data.Record/Ext.data.Record[]}
772 * @param {Number} index
775 destroyRecord : function(store, record, index) {
776 if (this.modified.indexOf(record) != -1) { // <-- handled already if @cfg pruneModifiedRecords == true
777 this.modified.remove(record);
779 if (!record.phantom) {
780 this.removed.push(record);
782 // since the record has already been removed from the store but the server request has not yet been executed,
783 // must keep track of the last known index this record existed. If a server error occurs, the record can be
784 // put back into the store. @see Store#createCallback where the record is returned when response status === false
785 record.lastIndex = index;
787 if (this.autoSave === true) {
794 * This method should generally not be used directly. This method is called internally
795 * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
796 * {@link #remove}, or {@link #update} events fire.
797 * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
798 * @param {Record/Record[]} rs
799 * @param {Object} options
803 execute : function(action, rs, options) {
804 // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
805 if (!Ext.data.Api.isAction(action)) {
806 throw new Ext.data.Api.Error('execute', action);
808 // make sure options has a params key
809 options = Ext.applyIf(options||{}, {
813 // have to separate before-events since load has a different signature than create,destroy and save events since load does not
814 // include the rs (record resultset) parameter. Capture return values from the beforeaction into doRequest flag.
815 var doRequest = true;
817 if (action === 'read') {
818 doRequest = this.fireEvent('beforeload', this, options);
821 // if Writer is configured as listful, force single-recoord rs to be [{}} instead of {}
822 if (this.writer.listful === true && this.restful !== true) {
823 rs = (Ext.isArray(rs)) ? rs : [rs];
825 // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
826 else if (Ext.isArray(rs) && rs.length == 1) {
829 // Write the action to options.params
830 if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
831 this.writer.write(action, options.params, rs);
834 if (doRequest !== false) {
835 // Send request to proxy.
836 var params = Ext.apply({}, options.params, this.baseParams);
837 if (this.writer && this.proxy.url && !this.proxy.restful && !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
838 params.xaction = action;
840 // Note: Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions. We'll flip it now
841 // and send the value into DataProxy#request, since it's the value which maps to the DataProxy#api
842 this.proxy.request(Ext.data.Api.actions[action], rs, params, this.reader, this.createCallback(action, rs), this, options);
847 <div id="method-Ext.data.Store-save"></div>/**
848 * Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
849 * the configured <code>{@link #url}</code> will be used.
852 * --------------- --------------------
853 * removed records Ext.data.Api.actions.destroy
854 * phantom records Ext.data.Api.actions.create
855 * {@link #getModifiedRecords modified records} Ext.data.Api.actions.update
857 * @TODO: Create extensions of Error class and send associated Record with thrown exceptions.
858 * e.g.: Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
862 throw new Ext.data.Store.Error('writer-undefined');
865 // DESTROY: First check for removed records. Records in this.removed are guaranteed non-phantoms. @see Store#remove
866 if (this.removed.length) {
867 this.doTransaction('destroy', this.removed);
870 // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
871 var rs = [].concat(this.getModifiedRecords());
872 if (!rs.length) { // Bail-out if empty...
876 // CREATE: Next check for phantoms within rs. splice-off and execute create.
878 for (var i = rs.length-1; i >= 0; i--) {
879 if (rs[i].phantom === true) {
880 var rec = rs.splice(i, 1).shift();
884 } else if (!rs[i].isValid()) { // <-- while we're here, splice-off any !isValid real records
888 // If we have valid phantoms, create them...
889 if (phantoms.length) {
890 this.doTransaction('create', phantoms);
893 // UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
895 this.doTransaction('update', rs);
900 // private. Simply wraps call to Store#execute in try/catch. Defers to Store#handleException on error. Loops if batch: false
901 doTransaction : function(action, rs) {
902 function transaction(records) {
904 this.execute(action, records);
906 this.handleException(e);
909 if (this.batch === false) {
910 for (var i = 0, len = rs.length; i < len; i++) {
911 transaction.call(this, rs[i]);
914 transaction.call(this, rs);
918 // @private callback-handler for remote CRUD actions
919 // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
920 createCallback : function(action, rs) {
921 var actions = Ext.data.Api.actions;
922 return (action == 'read') ? this.loadRecords : function(data, response, success) {
923 // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
924 this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, data);
925 // If success === false here, exception will have been called in DataProxy
926 if (success === true) {
927 this.fireEvent('write', this, action, data, response, rs);
932 // Clears records from modified array after an exception event.
933 // NOTE: records are left marked dirty. Do we want to commit them even though they were not updated/realized?
934 // TODO remove this method?
935 clearModified : function(rs) {
936 if (Ext.isArray(rs)) {
937 for (var n=rs.length-1;n>=0;n--) {
938 this.modified.splice(this.modified.indexOf(rs[n]), 1);
941 this.modified.splice(this.modified.indexOf(rs), 1);
945 // remap record ids in MixedCollection after records have been realized. @see Store#onCreateRecords, @see DataReader#realize
946 reMap : function(record) {
947 if (Ext.isArray(record)) {
948 for (var i = 0, len = record.length; i < len; i++) {
949 this.reMap(record[i]);
952 delete this.data.map[record._phid];
953 this.data.map[record.id] = record;
954 var index = this.data.keys.indexOf(record._phid);
955 this.data.keys.splice(index, 1, record.id);
960 // @protected onCreateRecord proxy callback for create action
961 onCreateRecords : function(success, rs, data) {
962 if (success === true) {
964 this.reader.realize(rs, data);
968 this.handleException(e);
969 if (Ext.isArray(rs)) {
970 // Recurse to run back into the try {}. DataReader#realize splices-off the rs until empty.
971 this.onCreateRecords(success, rs, data);
977 // @protected, onUpdateRecords proxy callback for update action
978 onUpdateRecords : function(success, rs, data) {
979 if (success === true) {
981 this.reader.update(rs, data);
983 this.handleException(e);
984 if (Ext.isArray(rs)) {
985 // Recurse to run back into the try {}. DataReader#update splices-off the rs until empty.
986 this.onUpdateRecords(success, rs, data);
992 // @protected onDestroyRecords proxy callback for destroy action
993 onDestroyRecords : function(success, rs, data) {
994 // splice each rec out of this.removed
995 rs = (rs instanceof Ext.data.Record) ? [rs] : rs;
996 for (var i=0,len=rs.length;i<len;i++) {
997 this.removed.splice(this.removed.indexOf(rs[i]), 1);
999 if (success === false) {
1000 // put records back into store if remote destroy fails.
1001 // @TODO: Might want to let developer decide.
1002 for (i=rs.length-1;i>=0;i--) {
1003 this.insert(rs[i].lastIndex, rs[i]); // <-- lastIndex set in Store#destroyRecord
1008 // protected handleException. Possibly temporary until Ext framework has an exception-handler.
1009 handleException : function(e) {
1010 // @see core/Error.js
1014 <div id="method-Ext.data.Store-reload"></div>/**
1015 * <p>Reloads the Record cache from the configured Proxy using the configured {@link Ext.data.Reader Reader} and
1016 * the options from the last load operation performed.</p>
1017 * <p><b>Note</b>: see the Important note in {@link #load}.</p>
1018 * @param {Object} options (optional) An <tt>Object</tt> containing {@link #load loading options} which may
1019 * override the options used in the last {@link #load} operation. See {@link #load} for details (defaults to
1020 * <tt>null</tt>, in which case the {@link #lastOptions} are used).
1022 reload : function(options){
1023 this.load(Ext.applyIf(options||{}, this.lastOptions));
1027 // Called as a callback by the Reader during a load operation.
1028 loadRecords : function(o, options, success){
1029 if(!o || success === false){
1030 if(success !== false){
1031 this.fireEvent('load', this, [], options);
1033 if(options.callback){
1034 options.callback.call(options.scope || this, [], options, false, o);
1038 var r = o.records, t = o.totalRecords || r.length;
1039 if(!options || options.add !== true){
1040 if(this.pruneModifiedRecords){
1043 for(var i = 0, len = r.length; i < len; i++){
1047 this.data = this.snapshot;
1048 delete this.snapshot;
1051 this.data.addAll(r);
1052 this.totalLength = t;
1054 this.fireEvent('datachanged', this);
1056 this.totalLength = Math.max(t, this.data.length+r.length);
1059 this.fireEvent('load', this, r, options);
1060 if(options.callback){
1061 options.callback.call(options.scope || this, r, options, true);
1065 <div id="method-Ext.data.Store-loadData"></div>/**
1066 * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
1067 * which understands the format of the data must have been configured in the constructor.
1068 * @param {Object} data The data block from which to read the Records. The format of the data expected
1069 * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
1070 * that {@link Ext.data.Reader Reader}'s <tt>{@link Ext.data.Reader#readRecords}</tt> parameter.
1071 * @param {Boolean} append (Optional) <tt>true</tt> to append the new Records rather the default to replace
1072 * the existing cache.
1073 * <b>Note</b>: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
1074 * with ids which are already present in the Store will <i>replace</i> existing Records. Only Records with
1075 * new, unique ids will be added.
1077 loadData : function(o, append){
1078 var r = this.reader.readRecords(o);
1079 this.loadRecords(r, {add: append}, true);
1082 <div id="method-Ext.data.Store-getCount"></div>/**
1083 * Gets the number of cached records.
1084 * <p>If using paging, this may not be the total size of the dataset. If the data object
1085 * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
1086 * the dataset size. <b>Note</b>: see the Important note in {@link #load}.</p>
1087 * @return {Number} The number of Records in the Store's cache.
1089 getCount : function(){
1090 return this.data.length || 0;
1093 <div id="method-Ext.data.Store-getTotalCount"></div>/**
1094 * Gets the total number of records in the dataset as returned by the server.
1095 * <p>If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
1096 * must contain the dataset size. For remote data sources, the value for this property
1097 * (<tt>totalProperty</tt> for {@link Ext.data.JsonReader JsonReader},
1098 * <tt>totalRecords</tt> for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
1099 * <b>Note</b>: see the Important note in {@link #load}.</p>
1100 * @return {Number} The number of Records as specified in the data object passed to the Reader
1102 * <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
1104 getTotalCount : function(){
1105 return this.totalLength || 0;
1108 <div id="method-Ext.data.Store-getSortState"></div>/**
1109 * Returns an object describing the current sort state of this Store.
1110 * @return {Object} The sort state of the Store. An object with two properties:<ul>
1111 * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>
1112 * <li><b>direction : String<p class="sub-desc">The sort order, 'ASC' or 'DESC' (case-sensitive).</p></li>
1114 * See <tt>{@link #sortInfo}</tt> for additional details.
1116 getSortState : function(){
1117 return this.sortInfo;
1121 applySort : function(){
1122 if(this.sortInfo && !this.remoteSort){
1123 var s = this.sortInfo, f = s.field;
1124 this.sortData(f, s.direction);
1129 sortData : function(f, direction){
1130 direction = direction || 'ASC';
1131 var st = this.fields.get(f).sortType;
1132 var fn = function(r1, r2){
1133 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
1134 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
1136 this.data.sort(direction, fn);
1137 if(this.snapshot && this.snapshot != this.data){
1138 this.snapshot.sort(direction, fn);
1142 <div id="method-Ext.data.Store-setDefaultSort"></div>/**
1143 * Sets the default sort column and order to be used by the next {@link #load} operation.
1144 * @param {String} fieldName The name of the field to sort by.
1145 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1147 setDefaultSort : function(field, dir){
1148 dir = dir ? dir.toUpperCase() : 'ASC';
1149 this.sortInfo = {field: field, direction: dir};
1150 this.sortToggle[field] = dir;
1153 <div id="method-Ext.data.Store-sort"></div>/**
1155 * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
1156 * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
1157 * @param {String} fieldName The name of the field to sort by.
1158 * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1160 sort : function(fieldName, dir){
1161 var f = this.fields.get(fieldName);
1166 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
1167 dir = (this.sortToggle[f.name] || 'ASC').toggle('ASC', 'DESC');
1172 var st = (this.sortToggle) ? this.sortToggle[f.name] : null;
1173 var si = (this.sortInfo) ? this.sortInfo : null;
1175 this.sortToggle[f.name] = dir;
1176 this.sortInfo = {field: f.name, direction: dir};
1177 if(!this.remoteSort){
1179 this.fireEvent('datachanged', this);
1181 if (!this.load(this.lastOptions)) {
1183 this.sortToggle[f.name] = st;
1192 <div id="method-Ext.data.Store-each"></div>/**
1193 * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
1194 * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
1195 * Returning <tt>false</tt> aborts and exits the iteration.
1196 * @param {Object} scope (optional) The scope in which to call the function (defaults to the {@link Ext.data.Record Record}).
1198 each : function(fn, scope){
1199 this.data.each(fn, scope);
1202 <div id="method-Ext.data.Store-getModifiedRecords"></div>/**
1203 * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are
1204 * persisted across load operations (e.g., during paging). <b>Note</b>: deleted records are not
1205 * included. See also <tt>{@link #pruneModifiedRecords}</tt> and
1206 * {@link Ext.data.Record}<tt>{@link Ext.data.Record#markDirty markDirty}.</tt>.
1207 * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
1208 * modifications. To obtain modified fields within a modified record see
1209 *{@link Ext.data.Record}<tt>{@link Ext.data.Record#modified modified}.</tt>.
1211 getModifiedRecords : function(){
1212 return this.modified;
1216 createFilterFn : function(property, value, anyMatch, caseSensitive){
1217 if(Ext.isEmpty(value, false)){
1220 value = this.data.createValueMatcher(value, anyMatch, caseSensitive);
1222 return value.test(r.data[property]);
1226 <div id="method-Ext.data.Store-sum"></div>/**
1227 * Sums the value of <tt>property</tt> for each {@link Ext.data.Record record} between <tt>start</tt>
1228 * and <tt>end</tt> and returns the result.
1229 * @param {String} property A field in each record
1230 * @param {Number} start (optional) The record index to start at (defaults to <tt>0</tt>)
1231 * @param {Number} end (optional) The last record index to include (defaults to length - 1)
1232 * @return {Number} The sum
1234 sum : function(property, start, end){
1235 var rs = this.data.items, v = 0;
1237 end = (end || end === 0) ? end : rs.length-1;
1239 for(var i = start; i <= end; i++){
1240 v += (rs[i].data[property] || 0);
1245 <div id="method-Ext.data.Store-filter"></div>/**
1246 * Filter the {@link Ext.data.Record records} by a specified property.
1247 * @param {String} field A field on your records
1248 * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
1249 * against the field.
1250 * @param {Boolean} anyMatch (optional) <tt>true</tt> to match any part not just the beginning
1251 * @param {Boolean} caseSensitive (optional) <tt>true</tt> for case sensitive comparison
1253 filter : function(property, value, anyMatch, caseSensitive){
1254 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1255 return fn ? this.filterBy(fn) : this.clearFilter();
1258 <div id="method-Ext.data.Store-filterBy"></div>/**
1259 * Filter by a function. The specified function will be called for each
1260 * Record in this Store. If the function returns <tt>true</tt> the Record is included,
1261 * otherwise it is filtered out.
1262 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1263 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1264 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1265 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1267 * @param {Object} scope (optional) The scope of the function (defaults to this)
1269 filterBy : function(fn, scope){
1270 this.snapshot = this.snapshot || this.data;
1271 this.data = this.queryBy(fn, scope||this);
1272 this.fireEvent('datachanged', this);
1275 <div id="method-Ext.data.Store-query"></div>/**
1276 * Query the records by a specified property.
1277 * @param {String} field A field on your records
1278 * @param {String/RegExp} value Either a string that the field
1279 * should begin with, or a RegExp to test against the field.
1280 * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
1281 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1282 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1284 query : function(property, value, anyMatch, caseSensitive){
1285 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1286 return fn ? this.queryBy(fn) : this.data.clone();
1289 <div id="method-Ext.data.Store-queryBy"></div>/**
1290 * Query the cached records in this Store using a filtering function. The specified function
1291 * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
1292 * included in the results.
1293 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1294 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1295 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1296 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1298 * @param {Object} scope (optional) The scope of the function (defaults to this)
1299 * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1301 queryBy : function(fn, scope){
1302 var data = this.snapshot || this.data;
1303 return data.filterBy(fn, scope||this);
1306 <div id="method-Ext.data.Store-find"></div>/**
1307 * Finds the index of the first matching record in this store by a specific property/value.
1308 * @param {String} property A property on your objects
1309 * @param {String/RegExp} value Either a string that the property value
1310 * should begin with, or a RegExp to test against the property.
1311 * @param {Number} startIndex (optional) The index to start searching at
1312 * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1313 * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1314 * @return {Number} The matched index or -1
1316 find : function(property, value, start, anyMatch, caseSensitive){
1317 var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1318 return fn ? this.data.findIndexBy(fn, null, start) : -1;
1321 <div id="method-Ext.data.Store-findExact"></div>/**
1322 * Finds the index of the first matching record in this store by a specific property/value.
1323 * @param {String} property A property on your objects
1324 * @param {String/RegExp} value The value to match against
1325 * @param {Number} startIndex (optional) The index to start searching at
1326 * @return {Number} The matched index or -1
1328 findExact: function(property, value, start){
1329 return this.data.findIndexBy(function(rec){
1330 return rec.get(property) === value;
1334 <div id="method-Ext.data.Store-findBy"></div>/**
1335 * Find the index of the first matching Record in this Store by a function.
1336 * If the function returns <tt>true</tt> it is considered a match.
1337 * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1338 * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1339 * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1340 * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1342 * @param {Object} scope (optional) The scope of the function (defaults to this)
1343 * @param {Number} startIndex (optional) The index to start searching at
1344 * @return {Number} The matched index or -1
1346 findBy : function(fn, scope, start){
1347 return this.data.findIndexBy(fn, scope, start);
1350 <div id="method-Ext.data.Store-collect"></div>/**
1351 * Collects unique values for a particular dataIndex from this store.
1352 * @param {String} dataIndex The property to collect
1353 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
1354 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
1355 * @return {Array} An array of the unique values
1357 collect : function(dataIndex, allowNull, bypassFilter){
1358 var d = (bypassFilter === true && this.snapshot) ?
1359 this.snapshot.items : this.data.items;
1360 var v, sv, r = [], l = {};
1361 for(var i = 0, len = d.length; i < len; i++){
1362 v = d[i].data[dataIndex];
1364 if((allowNull || !Ext.isEmpty(v)) && !l[sv]){
1372 <div id="method-Ext.data.Store-clearFilter"></div>/**
1373 * Revert to a view of the Record cache with no filtering applied.
1374 * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
1375 * {@link #datachanged} event.
1377 clearFilter : function(suppressEvent){
1378 if(this.isFiltered()){
1379 this.data = this.snapshot;
1380 delete this.snapshot;
1381 if(suppressEvent !== true){
1382 this.fireEvent('datachanged', this);
1387 <div id="method-Ext.data.Store-isFiltered"></div>/**
1388 * Returns true if this store is currently filtered
1391 isFiltered : function(){
1392 return this.snapshot && this.snapshot != this.data;
1396 afterEdit : function(record){
1397 if(this.modified.indexOf(record) == -1){
1398 this.modified.push(record);
1400 this.fireEvent('update', this, record, Ext.data.Record.EDIT);
1404 afterReject : function(record){
1405 this.modified.remove(record);
1406 this.fireEvent('update', this, record, Ext.data.Record.REJECT);
1410 afterCommit : function(record){
1411 this.modified.remove(record);
1412 this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
1415 <div id="method-Ext.data.Store-commitChanges"></div>/**
1416 * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
1417 * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
1418 * Ext.data.Record.COMMIT.
1420 commitChanges : function(){
1421 var m = this.modified.slice(0);
1423 for(var i = 0, len = m.length; i < len; i++){
1428 <div id="method-Ext.data.Store-rejectChanges"></div>/**
1429 * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
1431 rejectChanges : function(){
1432 var m = this.modified.slice(0);
1434 for(var i = 0, len = m.length; i < len; i++){
1437 var m = this.removed.slice(0).reverse();
1439 for(var i = 0, len = m.length; i < len; i++){
1440 this.insert(m[i].lastIndex||0, m[i]);
1446 onMetaChange : function(meta, rtype, o){
1447 this.recordType = rtype;
1448 this.fields = rtype.prototype.fields;
1449 delete this.snapshot;
1451 this.sortInfo = meta.sortInfo;
1452 }else if(this.sortInfo && !this.fields.get(this.sortInfo.field)){
1453 delete this.sortInfo;
1456 this.fireEvent('metachange', this, this.reader.meta);
1460 findInsertIndex : function(record){
1461 this.suspendEvents();
1462 var data = this.data.clone();
1463 this.data.add(record);
1465 var index = this.data.indexOf(record);
1467 this.resumeEvents();
1471 <div id="method-Ext.data.Store-setBaseParam"></div>/**
1472 * Set the value for a property name in this store's {@link #baseParams}. Usage:</p><pre><code>
1473 myStore.setBaseParam('foo', {bar:3});
1475 * @param {String} name Name of the property to assign
1476 * @param {Mixed} value Value to assign the <tt>name</tt>d property
1478 setBaseParam : function (name, value){
1479 this.baseParams = this.baseParams || {};
1480 this.baseParams[name] = value;
1484 Ext.reg('store', Ext.data.Store);
1486 <div id="cls-Ext.data.Store.Error"></div>/**
1487 * @class Ext.data.Store.Error
1488 * @extends Ext.Error
1489 * Store Error extension.
1490 * @param {String} name
1492 Ext.data.Store.Error = Ext.extend(Ext.Error, {
1493 name: 'Ext.data.Store'
1495 Ext.apply(Ext.data.Store.Error.prototype, {
1497 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'