Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / docs / source / Store.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.1
11  * Copyright(c) 2006-2010 Sencha Inc.
12  * licensing@sencha.com
13  * http://www.sencha.com/license
14  */
15 <div id="cls-Ext.data.Store"></div>/**
16  * @class Ext.data.Store
17  * @extends Ext.util.Observable
18  * <p>The Store class encapsulates a client side cache of {@link Ext.data.Record Record}
19  * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},
20  * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.</p>
21  * <p><u>Retrieving Data</u></p>
22  * <p>A Store object may access a data object using:<div class="mdetail-params"><ul>
23  * <li>{@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}</li>
24  * <li>{@link #data} to automatically pass in data</li>
25  * <li>{@link #loadData} to manually pass in data</li>
26  * </ul></div></p>
27  * <p><u>Reading Data</u></p>
28  * <p>A Store object has no inherent knowledge of the format of the data object (it could be
29  * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation}
30  * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data
31  * object.</p>
32  * <p><u>Store Types</u></p>
33  * <p>There are several implementations of Store available which are customized for use with
34  * a specific DataReader implementation.  Here is an example using an ArrayStore which implicitly
35  * creates a reader commensurate to an Array data object.</p>
36  * <pre><code>
37 var myStore = new Ext.data.ArrayStore({
38     fields: ['fullname', 'first'],
39     idIndex: 0 // id for each record will be the first element
40 });
41  * </code></pre>
42  * <p>For custom implementations create a basic {@link Ext.data.Store} configured as needed:</p>
43  * <pre><code>
44 // create a {@link Ext.data.Record Record} constructor:
45 var rt = Ext.data.Record.create([
46     {name: 'fullname'},
47     {name: 'first'}
48 ]);
49 var myStore = new Ext.data.Store({
50     // explicitly create reader
51     reader: new Ext.data.ArrayReader(
52         {
53             idIndex: 0  // id for each record will be the first element
54         },
55         rt // recordType
56     )
57 });
58  * </code></pre>
59  * <p>Load some data into store (note the data object is an array which corresponds to the reader):</p>
60  * <pre><code>
61 var myData = [
62     [1, 'Fred Flintstone', 'Fred'],  // note that id for the record is the first element
63     [2, 'Barney Rubble', 'Barney']
64 ];
65 myStore.loadData(myData);
66  * </code></pre>
67  * <p>Records are cached and made available through accessor functions.  An example of adding
68  * a record to the store:</p>
69  * <pre><code>
70 var defaultData = {
71     fullname: 'Full Name',
72     first: 'First Name'
73 };
74 var recId = 100; // provide unique id for the record
75 var r = new myStore.recordType(defaultData, ++recId); // create new record
76 myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add})
77  * </code></pre>
78  * <p><u>Writing Data</u></p>
79  * <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>
80  * along with <a href="http://extjs.com/deploy/dev/examples/restful/restful.html">RESTful features.</a>
81  * @constructor
82  * Creates a new Store.
83  * @param {Object} config A config object containing the objects needed for the Store to access data,
84  * and read the data into Records.
85  * @xtype store
86  */
87 Ext.data.Store = Ext.extend(Ext.util.Observable, {
88     <div id="cfg-Ext.data.Store-storeId"></div>/**
89      * @cfg {String} storeId If passed, the id to use to register with the <b>{@link Ext.StoreMgr StoreMgr}</b>.
90      * <p><b>Note</b>: if a (deprecated) <tt>{@link #id}</tt> is specified it will supersede the <tt>storeId</tt>
91      * assignment.</p>
92      */
93     <div id="cfg-Ext.data.Store-url"></div>/**
94      * @cfg {String} url If a <tt>{@link #proxy}</tt> is not specified the <tt>url</tt> will be used to
95      * implicitly configure a {@link Ext.data.HttpProxy HttpProxy} if an <tt>url</tt> is specified.
96      * Typically this option, or the <code>{@link #data}</code> option will be specified.
97      */
98     <div id="cfg-Ext.data.Store-autoLoad"></div>/**
99      * @cfg {Boolean/Object} autoLoad If <tt>{@link #data}</tt> is not specified, and if <tt>autoLoad</tt>
100      * is <tt>true</tt> or an <tt>Object</tt>, this store's {@link #load} method is automatically called
101      * after creation. If the value of <tt>autoLoad</tt> is an <tt>Object</tt>, this <tt>Object</tt> will
102      * be passed to the store's {@link #load} method.
103      */
104     <div id="cfg-Ext.data.Store-proxy"></div>/**
105      * @cfg {Ext.data.DataProxy} proxy The {@link Ext.data.DataProxy DataProxy} object which provides
106      * access to a data object.  See <code>{@link #url}</code>.
107      */
108     <div id="cfg-Ext.data.Store-data"></div>/**
109      * @cfg {Array} data An inline data object readable by the <code>{@link #reader}</code>.
110      * Typically this option, or the <code>{@link #url}</code> option will be specified.
111      */
112     <div id="cfg-Ext.data.Store-reader"></div>/**
113      * @cfg {Ext.data.DataReader} reader The {@link Ext.data.DataReader Reader} object which processes the
114      * data object and returns an Array of {@link Ext.data.Record} objects which are cached keyed by their
115      * <b><tt>{@link Ext.data.Record#id id}</tt></b> property.
116      */
117     <div id="cfg-Ext.data.Store-writer"></div>/**
118      * @cfg {Ext.data.DataWriter} writer
119      * <p>The {@link Ext.data.DataWriter Writer} object which processes a record object for being written
120      * to the server-side database.</p>
121      * <br><p>When a writer is installed into a Store the {@link #add}, {@link #remove}, and {@link #update}
122      * events on the store are monitored in order to remotely {@link #createRecords create records},
123      * {@link #destroyRecord destroy records}, or {@link #updateRecord update records}.</p>
124      * <br><p>The proxy for this store will relay any {@link #writexception} events to this store.</p>
125      * <br><p>Sample implementation:
126      * <pre><code>
127 var writer = new {@link Ext.data.JsonWriter}({
128     encode: true,
129     writeAllFields: true // write all fields, not just those that changed
130 });
131
132 // Typical Store collecting the Proxy, Reader and Writer together.
133 var store = new Ext.data.Store({
134     storeId: 'user',
135     root: 'records',
136     proxy: proxy,
137     reader: reader,
138     writer: writer,     // <-- plug a DataWriter into the store just as you would a Reader
139     paramsAsHash: true,
140     autoSave: false    // <-- false to delay executing create, update, destroy requests
141                         //     until specifically told to do so.
142 });
143      * </code></pre></p>
144      */
145     writer : undefined,
146     <div id="cfg-Ext.data.Store-baseParams"></div>/**
147      * @cfg {Object} baseParams
148      * <p>An object containing properties which are to be sent as parameters
149      * for <i>every</i> HTTP request.</p>
150      * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
151      * <p><b>Note</b>: <code>baseParams</code> may be superseded by any <code>params</code>
152      * specified in a <code>{@link #load}</code> request, see <code>{@link #load}</code>
153      * for more details.</p>
154      * This property may be modified after creation using the <code>{@link #setBaseParam}</code>
155      * method.
156      * @property
157      */
158     <div id="cfg-Ext.data.Store-sortInfo"></div>/**
159      * @cfg {Object} sortInfo A config object to specify the sort order in the request of a Store's
160      * {@link #load} operation.  Note that for local sorting, the <tt>direction</tt> property is
161      * case-sensitive. See also {@link #remoteSort} and {@link #paramNames}.
162      * For example:<pre><code>
163 sortInfo: {
164     field: 'fieldName',
165     direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
166 }
167 </code></pre>
168      */
169     <div id="cfg-Ext.data.Store-remoteSort"></div>/**
170      * @cfg {boolean} remoteSort <tt>true</tt> if sorting is to be handled by requesting the <tt>{@link #proxy Proxy}</tt>
171      * to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
172      * in place (defaults to <tt>false</tt>).
173      * <p>If <tt>remoteSort</tt> is <tt>true</tt>, then clicking on a {@link Ext.grid.Column Grid Column}'s
174      * {@link Ext.grid.Column#header header} causes the current page to be requested from the server appending
175      * the following two parameters to the <b><tt>{@link #load params}</tt></b>:<div class="mdetail-params"><ul>
176      * <li><b><tt>sort</tt></b> : String<p class="sub-desc">The <tt>name</tt> (as specified in the Record's
177      * {@link Ext.data.Field Field definition}) of the field to sort on.</p></li>
178      * <li><b><tt>dir</tt></b> : String<p class="sub-desc">The direction of the sort, 'ASC' or 'DESC' (case-sensitive).</p></li>
179      * </ul></div></p>
180      */
181     remoteSort : false,
182
183     <div id="cfg-Ext.data.Store-autoDestroy"></div>/**
184      * @cfg {Boolean} autoDestroy <tt>true</tt> to destroy the store when the component the store is bound
185      * to is destroyed (defaults to <tt>false</tt>).
186      * <p><b>Note</b>: this should be set to true when using stores that are bound to only 1 component.</p>
187      */
188     autoDestroy : false,
189
190     <div id="cfg-Ext.data.Store-pruneModifiedRecords"></div>/**
191      * @cfg {Boolean} pruneModifiedRecords <tt>true</tt> to clear all modified record information each time
192      * the store is loaded or when a record is removed (defaults to <tt>false</tt>). See {@link #getModifiedRecords}
193      * for the accessor method to retrieve the modified records.
194      */
195     pruneModifiedRecords : false,
196
197     <div id="prop-Ext.data.Store-lastOptions"></div>/**
198      * Contains the last options object used as the parameter to the {@link #load} method. See {@link #load}
199      * for the details of what this may contain. This may be useful for accessing any params which were used
200      * to load the current Record cache.
201      * @property
202      */
203     lastOptions : null,
204
205     <div id="cfg-Ext.data.Store-autoSave"></div>/**
206      * @cfg {Boolean} autoSave
207      * <p>Defaults to <tt>true</tt> causing the store to automatically {@link #save} records to
208      * the server when a record is modified (ie: becomes 'dirty'). Specify <tt>false</tt> to manually call {@link #save}
209      * to send all modifiedRecords to the server.</p>
210      * <br><p><b>Note</b>: each CRUD action will be sent as a separate request.</p>
211      */
212     autoSave : true,
213
214     <div id="cfg-Ext.data.Store-batch"></div>/**
215      * @cfg {Boolean} batch
216      * <p>Defaults to <tt>true</tt> (unless <code>{@link #restful}:true</code>). Multiple
217      * requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) will be combined
218      * and sent as one transaction. Only applies when <code>{@link #autoSave}</code> is set
219      * to <tt>false</tt>.</p>
220      * <br><p>If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is
221      * generated for each record.</p>
222      */
223     batch : true,
224
225     <div id="cfg-Ext.data.Store-restful"></div>/**
226      * @cfg {Boolean} restful
227      * Defaults to <tt>false</tt>.  Set to <tt>true</tt> to have the Store and the set
228      * Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
229      * PUT and DELETE requests to the server. The HTTP method used for any given CRUD
230      * action is described in {@link Ext.data.Api#restActions}.  For additional information
231      * see {@link Ext.data.DataProxy#restful}.
232      * <p><b>Note</b>: if <code>{@link #restful}:true</code> <code>batch</code> will
233      * internally be set to <tt>false</tt>.</p>
234      */
235     restful: false,
236
237     <div id="cfg-Ext.data.Store-paramNames"></div>/**
238      * @cfg {Object} paramNames
239      * <p>An object containing properties which specify the names of the paging and
240      * sorting parameters passed to remote servers when loading blocks of data. By default, this
241      * object takes the following form:</p><pre><code>
242 {
243     start : 'start',  // The parameter name which specifies the start row
244     limit : 'limit',  // The parameter name which specifies number of rows to return
245     sort : 'sort',    // The parameter name which specifies the column to sort on
246     dir : 'dir'       // The parameter name which specifies the sort direction
247 }
248 </code></pre>
249      * <p>The server must produce the requested data block upon receipt of these parameter names.
250      * If different parameter names are required, this property can be overriden using a configuration
251      * property.</p>
252      * <p>A {@link Ext.PagingToolbar PagingToolbar} bound to this Store uses this property to determine
253      * the parameter names to use in its {@link #load requests}.
254      */
255     paramNames : undefined,
256
257     <div id="cfg-Ext.data.Store-defaultParamNames"></div>/**
258      * @cfg {Object} defaultParamNames
259      * Provides the default values for the {@link #paramNames} property. To globally modify the parameters
260      * for all stores, this object should be changed on the store prototype.
261      */
262     defaultParamNames : {
263         start : 'start',
264         limit : 'limit',
265         sort : 'sort',
266         dir : 'dir'
267     },
268
269     isDestroyed: false,    
270     hasMultiSort: false,
271
272     // private
273     batchKey : '_ext_batch_',
274
275     constructor : function(config){
276         <div id="prop-Ext.data.Store-multiSort"></div>/**
277          * @property multiSort
278          * @type Boolean
279          * True if this store is currently sorted by more than one field/direction combination.
280          */
281         
282         <div id="prop-Ext.data.Store-isDestroyed"></div>/**
283          * @property isDestroyed
284          * @type Boolean
285          * True if the store has been destroyed already. Read only
286          */
287         
288         this.data = new Ext.util.MixedCollection(false);
289         this.data.getKey = function(o){
290             return o.id;
291         };
292         
293
294         // temporary removed-records cache
295         this.removed = [];
296
297         if(config && config.data){
298             this.inlineData = config.data;
299             delete config.data;
300         }
301
302         Ext.apply(this, config);
303
304         <div id="prop-Ext.data.Store-baseParams"></div>/**
305          * See the <code>{@link #baseParams corresponding configuration option}</code>
306          * for a description of this property.
307          * To modify this property see <code>{@link #setBaseParam}</code>.
308          * @property
309          */
310         this.baseParams = Ext.isObject(this.baseParams) ? this.baseParams : {};
311
312         this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
313
314         if((this.url || this.api) && !this.proxy){
315             this.proxy = new Ext.data.HttpProxy({url: this.url, api: this.api});
316         }
317         // If Store is RESTful, so too is the DataProxy
318         if (this.restful === true && this.proxy) {
319             // When operating RESTfully, a unique transaction is generated for each record.
320             // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
321             this.batch = false;
322             Ext.data.Api.restify(this.proxy);
323         }
324
325         if(this.reader){ // reader passed
326             if(!this.recordType){
327                 this.recordType = this.reader.recordType;
328             }
329             if(this.reader.onMetaChange){
330                 this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
331             }
332             if (this.writer) { // writer passed
333                 if (this.writer instanceof(Ext.data.DataWriter) === false) {    // <-- config-object instead of instance.
334                     this.writer = this.buildWriter(this.writer);
335                 }
336                 this.writer.meta = this.reader.meta;
337                 this.pruneModifiedRecords = true;
338             }
339         }
340
341         <div id="prop-Ext.data.Store-recordType"></div>/**
342          * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
343          * {@link Ext.data.DataReader Reader}. Read-only.
344          * <p>If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
345          * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
346          * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).</p>
347          * <p>This property may be used to create new Records of the type held in this Store, for example:</p><pre><code>
348     // create the data store
349     var store = new Ext.data.ArrayStore({
350         autoDestroy: true,
351         fields: [
352            {name: 'company'},
353            {name: 'price', type: 'float'},
354            {name: 'change', type: 'float'},
355            {name: 'pctChange', type: 'float'},
356            {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
357         ]
358     });
359     store.loadData(myData);
360
361     // create the Grid
362     var grid = new Ext.grid.EditorGridPanel({
363         store: store,
364         colModel: new Ext.grid.ColumnModel({
365             columns: [
366                 {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
367                 {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
368                 {header: 'Change', renderer: change, dataIndex: 'change'},
369                 {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
370                 {header: 'Last Updated', width: 85,
371                     renderer: Ext.util.Format.dateRenderer('m/d/Y'),
372                     dataIndex: 'lastChange'}
373             ],
374             defaults: {
375                 sortable: true,
376                 width: 75
377             }
378         }),
379         autoExpandColumn: 'company', // match the id specified in the column model
380         height:350,
381         width:600,
382         title:'Array Grid',
383         tbar: [{
384             text: 'Add Record',
385             handler : function(){
386                 var defaultData = {
387                     change: 0,
388                     company: 'New Company',
389                     lastChange: (new Date()).clearTime(),
390                     pctChange: 0,
391                     price: 10
392                 };
393                 var recId = 3; // provide unique id
394                 var p = new store.recordType(defaultData, recId); // create new record
395                 grid.stopEditing();
396                 store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
397                 grid.startEditing(0, 0);
398             }
399         }]
400     });
401          * </code></pre>
402          * @property recordType
403          * @type Function
404          */
405
406         if(this.recordType){
407             <div id="prop-Ext.data.Store-fields"></div>/**
408              * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
409              * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
410              * @property fields
411              * @type Ext.util.MixedCollection
412              */
413             this.fields = this.recordType.prototype.fields;
414         }
415         this.modified = [];
416
417         this.addEvents(
418             <div id="event-Ext.data.Store-datachanged"></div>/**
419              * @event datachanged
420              * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
421              * widget that is using this Store as a Record cache should refresh its view.
422              * @param {Store} this
423              */
424             'datachanged',
425             <div id="event-Ext.data.Store-metachange"></div>/**
426              * @event metachange
427              * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
428              * @param {Store} this
429              * @param {Object} meta The JSON metadata
430              */
431             'metachange',
432             <div id="event-Ext.data.Store-add"></div>/**
433              * @event add
434              * Fires when Records have been {@link #add}ed to the Store
435              * @param {Store} this
436              * @param {Ext.data.Record[]} records The array of Records added
437              * @param {Number} index The index at which the record(s) were added
438              */
439             'add',
440             <div id="event-Ext.data.Store-remove"></div>/**
441              * @event remove
442              * Fires when a Record has been {@link #remove}d from the Store
443              * @param {Store} this
444              * @param {Ext.data.Record} record The Record that was removed
445              * @param {Number} index The index at which the record was removed
446              */
447             'remove',
448             <div id="event-Ext.data.Store-update"></div>/**
449              * @event update
450              * Fires when a Record has been updated
451              * @param {Store} this
452              * @param {Ext.data.Record} record The Record that was updated
453              * @param {String} operation The update operation being performed.  Value may be one of:
454              * <pre><code>
455      Ext.data.Record.EDIT
456      Ext.data.Record.REJECT
457      Ext.data.Record.COMMIT
458              * </code></pre>
459              */
460             'update',
461             <div id="event-Ext.data.Store-clear"></div>/**
462              * @event clear
463              * Fires when the data cache has been cleared.
464              * @param {Store} this
465              * @param {Record[]} records The records that were cleared.
466              */
467             'clear',
468             <div id="event-Ext.data.Store-exception"></div>/**
469              * @event exception
470              * <p>Fires if an exception occurs in the Proxy during a remote request.
471              * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
472              * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
473              * for additional details.
474              * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
475              * for description.
476              */
477             'exception',
478             <div id="event-Ext.data.Store-beforeload"></div>/**
479              * @event beforeload
480              * Fires before a request is made for a new data object.  If the beforeload handler returns
481              * <tt>false</tt> the {@link #load} action will be canceled.
482              * @param {Store} this
483              * @param {Object} options The loading options that were specified (see {@link #load} for details)
484              */
485             'beforeload',
486             <div id="event-Ext.data.Store-load"></div>/**
487              * @event load
488              * Fires after a new set of Records has been loaded.
489              * @param {Store} this
490              * @param {Ext.data.Record[]} records The Records that were loaded
491              * @param {Object} options The loading options that were specified (see {@link #load} for details)
492              */
493             'load',
494             <div id="event-Ext.data.Store-loadexception"></div>/**
495              * @event loadexception
496              * <p>This event is <b>deprecated</b> in favor of the catch-all <b><code>{@link #exception}</code></b>
497              * event instead.</p>
498              * <p>This event is relayed through the corresponding {@link Ext.data.DataProxy}.
499              * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
500              * for additional details.
501              * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
502              * for description.
503              */
504             'loadexception',
505             <div id="event-Ext.data.Store-beforewrite"></div>/**
506              * @event beforewrite
507              * @param {Ext.data.Store} store
508              * @param {String} action [Ext.data.Api.actions.create|update|destroy]
509              * @param {Record/Record[]} rs The Record(s) being written.
510              * @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)
511              * @param {Object} arg The callback's arg object passed to the {@link #request} function
512              */
513             'beforewrite',
514             <div id="event-Ext.data.Store-write"></div>/**
515              * @event write
516              * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
517              * Success of the action is determined in the <code>result['successProperty']</code>property (<b>NOTE</b> for RESTful stores,
518              * a simple 20x response is sufficient for the actions "destroy" and "update".  The "create" action should should return 200 along with a database pk).
519              * @param {Ext.data.Store} store
520              * @param {String} action [Ext.data.Api.actions.create|update|destroy]
521              * @param {Object} result The 'data' picked-out out of the response for convenience.
522              * @param {Ext.Direct.Transaction} res
523              * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
524              */
525             'write',
526             <div id="event-Ext.data.Store-beforesave"></div>/**
527              * @event beforesave
528              * Fires before a save action is called. A save encompasses destroying records, updating records and creating records.
529              * @param {Ext.data.Store} store
530              * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
531              * with an array of records for each action.
532              */
533             'beforesave',
534             <div id="event-Ext.data.Store-save"></div>/**
535              * @event save
536              * Fires after a save is completed. A save encompasses destroying records, updating records and creating records.
537              * @param {Ext.data.Store} store
538              * @param {Number} batch The identifier for the batch that was saved.
539              * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
540              * with an array of records for each action.
541              */
542             'save'
543
544         );
545
546         if(this.proxy){
547             // TODO remove deprecated loadexception with ext-3.0.1
548             this.relayEvents(this.proxy,  ['loadexception', 'exception']);
549         }
550         // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
551         if (this.writer) {
552             this.on({
553                 scope: this,
554                 add: this.createRecords,
555                 remove: this.destroyRecord,
556                 update: this.updateRecord,
557                 clear: this.onClear
558             });
559         }
560
561         this.sortToggle = {};
562         if(this.sortField){
563             this.setDefaultSort(this.sortField, this.sortDir);
564         }else if(this.sortInfo){
565             this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
566         }
567
568         Ext.data.Store.superclass.constructor.call(this);
569
570         if(this.id){
571             this.storeId = this.id;
572             delete this.id;
573         }
574         if(this.storeId){
575             Ext.StoreMgr.register(this);
576         }
577         if(this.inlineData){
578             this.loadData(this.inlineData);
579             delete this.inlineData;
580         }else if(this.autoLoad){
581             this.load.defer(10, this, [
582                 typeof this.autoLoad == 'object' ?
583                     this.autoLoad : undefined]);
584         }
585         // used internally to uniquely identify a batch
586         this.batchCounter = 0;
587         this.batches = {};
588     },
589
590     /**
591      * builds a DataWriter instance when Store constructor is provided with a writer config-object instead of an instace.
592      * @param {Object} config Writer configuration
593      * @return {Ext.data.DataWriter}
594      * @private
595      */
596     buildWriter : function(config) {
597         var klass = undefined,
598             type = (config.format || 'json').toLowerCase();
599         switch (type) {
600             case 'json':
601                 klass = Ext.data.JsonWriter;
602                 break;
603             case 'xml':
604                 klass = Ext.data.XmlWriter;
605                 break;
606             default:
607                 klass = Ext.data.JsonWriter;
608         }
609         return new klass(config);
610     },
611
612     <div id="method-Ext.data.Store-destroy"></div>/**
613      * Destroys the store.
614      */
615     destroy : function(){
616         if(!this.isDestroyed){
617             if(this.storeId){
618                 Ext.StoreMgr.unregister(this);
619             }
620             this.clearData();
621             this.data = null;
622             Ext.destroy(this.proxy);
623             this.reader = this.writer = null;
624             this.purgeListeners();
625             this.isDestroyed = true;
626         }
627     },
628
629     <div id="method-Ext.data.Store-add"></div>/**
630      * Add Records to the Store and fires the {@link #add} event.  To add Records
631      * to the store from a remote source use <code>{@link #load}({add:true})</code>.
632      * See also <code>{@link #recordType}</code> and <code>{@link #insert}</code>.
633      * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
634      * to add to the cache. See {@link #recordType}.
635      */
636     add : function(records) {
637         var i, len, record, index;
638         
639         records = [].concat(records);
640         if (records.length < 1) {
641             return;
642         }
643         
644         for (i = 0, len = records.length; i < len; i++) {
645             record = records[i];
646             
647             record.join(this);
648             
649             if (record.dirty || record.phantom) {
650                 this.modified.push(record);
651             }
652         }
653         
654         index = this.data.length;
655         this.data.addAll(records);
656         
657         if (this.snapshot) {
658             this.snapshot.addAll(records);
659         }
660         
661         this.fireEvent('add', this, records, index);
662     },
663
664     <div id="method-Ext.data.Store-addSorted"></div>/**
665      * (Local sort only) Inserts the passed Record into the Store at the index where it
666      * should go based on the current sort information.
667      * @param {Ext.data.Record} record
668      */
669     addSorted : function(record){
670         var index = this.findInsertIndex(record);
671         this.insert(index, record);
672     },
673     
674     /**
675      * @private
676      * Update a record within the store with a new reference
677      */
678     doUpdate : function(rec){
679         this.data.replace(rec.id, rec);
680         if(this.snapshot){
681             this.snapshot.replace(rec.id, rec);
682         }
683         this.fireEvent('update', this, rec, Ext.data.Record.COMMIT);
684     },
685
686     <div id="method-Ext.data.Store-remove"></div>/**
687      * Remove Records from the Store and fires the {@link #remove} event.
688      * @param {Ext.data.Record/Ext.data.Record[]} record The record object or array of records to remove from the cache.
689      */
690     remove : function(record){
691         if(Ext.isArray(record)){
692             Ext.each(record, function(r){
693                 this.remove(r);
694             }, this);
695             return;
696         }
697         var index = this.data.indexOf(record);
698         if(index > -1){
699             record.join(null);
700             this.data.removeAt(index);
701         }
702         if(this.pruneModifiedRecords){
703             this.modified.remove(record);
704         }
705         if(this.snapshot){
706             this.snapshot.remove(record);
707         }
708         if(index > -1){
709             this.fireEvent('remove', this, record, index);
710         }
711     },
712
713     <div id="method-Ext.data.Store-removeAt"></div>/**
714      * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
715      * @param {Number} index The index of the record to remove.
716      */
717     removeAt : function(index){
718         this.remove(this.getAt(index));
719     },
720
721     <div id="method-Ext.data.Store-removeAll"></div>/**
722      * Remove all Records from the Store and fires the {@link #clear} event.
723      * @param {Boolean} silent [false] Defaults to <tt>false</tt>.  Set <tt>true</tt> to not fire clear event.
724      */
725     removeAll : function(silent){
726         var items = [];
727         this.each(function(rec){
728             items.push(rec);
729         });
730         this.clearData();
731         if(this.snapshot){
732             this.snapshot.clear();
733         }
734         if(this.pruneModifiedRecords){
735             this.modified = [];
736         }
737         if (silent !== true) {  // <-- prevents write-actions when we just want to clear a store.
738             this.fireEvent('clear', this, items);
739         }
740     },
741
742     // private
743     onClear: function(store, records){
744         Ext.each(records, function(rec, index){
745             this.destroyRecord(this, rec, index);
746         }, this);
747     },
748
749     <div id="method-Ext.data.Store-insert"></div>/**
750      * Inserts Records into the Store at the given index and fires the {@link #add} event.
751      * See also <code>{@link #add}</code> and <code>{@link #addSorted}</code>.
752      * @param {Number} index The start index at which to insert the passed Records.
753      * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
754      */
755     insert : function(index, records) {
756         var i, len, record;
757         
758         records = [].concat(records);
759         for (i = 0, len = records.length; i < len; i++) {
760             record = records[i];
761             
762             this.data.insert(index + i, record);
763             record.join(this);
764             
765             if (record.dirty || record.phantom) {
766                 this.modified.push(record);
767             }
768         }
769         
770         if (this.snapshot) {
771             this.snapshot.addAll(records);
772         }
773         
774         this.fireEvent('add', this, records, index);
775     },
776
777     <div id="method-Ext.data.Store-indexOf"></div>/**
778      * Get the index within the cache of the passed Record.
779      * @param {Ext.data.Record} record The Ext.data.Record object to find.
780      * @return {Number} The index of the passed Record. Returns -1 if not found.
781      */
782     indexOf : function(record){
783         return this.data.indexOf(record);
784     },
785
786     <div id="method-Ext.data.Store-indexOfId"></div>/**
787      * Get the index within the cache of the Record with the passed id.
788      * @param {String} id The id of the Record to find.
789      * @return {Number} The index of the Record. Returns -1 if not found.
790      */
791     indexOfId : function(id){
792         return this.data.indexOfKey(id);
793     },
794
795     <div id="method-Ext.data.Store-getById"></div>/**
796      * Get the Record with the specified id.
797      * @param {String} id The id of the Record to find.
798      * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
799      */
800     getById : function(id){
801         return (this.snapshot || this.data).key(id);
802     },
803
804     <div id="method-Ext.data.Store-getAt"></div>/**
805      * Get the Record at the specified index.
806      * @param {Number} index The index of the Record to find.
807      * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
808      */
809     getAt : function(index){
810         return this.data.itemAt(index);
811     },
812
813     <div id="method-Ext.data.Store-getRange"></div>/**
814      * Returns a range of Records between specified indices.
815      * @param {Number} startIndex (optional) The starting index (defaults to 0)
816      * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
817      * @return {Ext.data.Record[]} An array of Records
818      */
819     getRange : function(start, end){
820         return this.data.getRange(start, end);
821     },
822
823     // private
824     storeOptions : function(o){
825         o = Ext.apply({}, o);
826         delete o.callback;
827         delete o.scope;
828         this.lastOptions = o;
829     },
830
831     // private
832     clearData: function(){
833         this.data.each(function(rec) {
834             rec.join(null);
835         });
836         this.data.clear();
837     },
838
839     <div id="method-Ext.data.Store-load"></div>/**
840      * <p>Loads the Record cache from the configured <tt>{@link #proxy}</tt> using the configured <tt>{@link #reader}</tt>.</p>
841      * <br><p>Notes:</p><div class="mdetail-params"><ul>
842      * <li><b><u>Important</u></b>: loading is asynchronous! This call will return before the new data has been
843      * loaded. To perform any post-processing where information from the load call is required, specify
844      * the <tt>callback</tt> function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.</li>
845      * <li>If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the <tt>start</tt> and <tt>limit</tt>
846      * properties in the <code>options.params</code> property to establish the initial position within the
847      * dataset, and the number of Records to cache on each read from the Proxy.</li>
848      * <li>If using {@link #remoteSort remote sorting}, the configured <code>{@link #sortInfo}</code>
849      * will be automatically included with the posted parameters according to the specified
850      * <code>{@link #paramNames}</code>.</li>
851      * </ul></div>
852      * @param {Object} options An object containing properties which control loading options:<ul>
853      * <li><b><tt>params</tt></b> :Object<div class="sub-desc"><p>An object containing properties to pass as HTTP
854      * parameters to a remote data source. <b>Note</b>: <code>params</code> will override any
855      * <code>{@link #baseParams}</code> of the same name.</p>
856      * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
857      * <li><b>callback</b> : Function<div class="sub-desc"><p>A function to be called after the Records
858      * have been loaded. The callback is called after the load event is fired, and is passed the following arguments:<ul>
859      * <li>r : Ext.data.Record[] An Array of Records loaded.</li>
860      * <li>options : Options object from the load call.</li>
861      * <li>success : Boolean success indicator.</li></ul></p></div></li>
862      * <li><b>scope</b> : Object<div class="sub-desc"><p>Scope with which to call the callback (defaults
863      * to the Store object)</p></div></li>
864      * <li><b>add</b> : Boolean<div class="sub-desc"><p>Indicator to append loaded records rather than
865      * replace the current cache.  <b>Note</b>: see note for <tt>{@link #loadData}</tt></p></div></li>
866      * </ul>
867      * @return {Boolean} If the <i>developer</i> provided <tt>{@link #beforeload}</tt> event handler returns
868      * <tt>false</tt>, the load call will abort and will return <tt>false</tt>; otherwise will return <tt>true</tt>.
869      */
870     load : function(options) {
871         options = Ext.apply({}, options);
872         this.storeOptions(options);
873         if(this.sortInfo && this.remoteSort){
874             var pn = this.paramNames;
875             options.params = Ext.apply({}, options.params);
876             options.params[pn.sort] = this.sortInfo.field;
877             options.params[pn.dir] = this.sortInfo.direction;
878         }
879         try {
880             return this.execute('read', null, options); // <-- null represents rs.  No rs for load actions.
881         } catch(e) {
882             this.handleException(e);
883             return false;
884         }
885     },
886
887     /**
888      * updateRecord  Should not be used directly.  This method will be called automatically if a Writer is set.
889      * Listens to 'update' event.
890      * @param {Object} store
891      * @param {Object} record
892      * @param {Object} action
893      * @private
894      */
895     updateRecord : function(store, record, action) {
896         if (action == Ext.data.Record.EDIT && this.autoSave === true && (!record.phantom || (record.phantom && record.isValid()))) {
897             this.save();
898         }
899     },
900
901     /**
902      * @private
903      * Should not be used directly.  Store#add will call this automatically if a Writer is set
904      * @param {Object} store
905      * @param {Object} records
906      * @param {Object} index
907      */
908     createRecords : function(store, records, index) {
909         var modified = this.modified,
910             length   = records.length,
911             record, i;
912         
913         for (i = 0; i < length; i++) {
914             record = records[i];
915             
916             if (record.phantom && record.isValid()) {
917                 record.markDirty();  // <-- Mark new records dirty (Ed: why?)
918                 
919                 if (modified.indexOf(record) == -1) {
920                     modified.push(record);
921                 }
922             }
923         }
924         if (this.autoSave === true) {
925             this.save();
926         }
927     },
928
929     /**
930      * Destroys a Record.  Should not be used directly.  It's called by Store#remove if a Writer is set.
931      * @param {Store} store this
932      * @param {Ext.data.Record} record
933      * @param {Number} index
934      * @private
935      */
936     destroyRecord : function(store, record, index) {
937         if (this.modified.indexOf(record) != -1) {  // <-- handled already if @cfg pruneModifiedRecords == true
938             this.modified.remove(record);
939         }
940         if (!record.phantom) {
941             this.removed.push(record);
942
943             // since the record has already been removed from the store but the server request has not yet been executed,
944             // must keep track of the last known index this record existed.  If a server error occurs, the record can be
945             // put back into the store.  @see Store#createCallback where the record is returned when response status === false
946             record.lastIndex = index;
947
948             if (this.autoSave === true) {
949                 this.save();
950             }
951         }
952     },
953
954     /**
955      * This method should generally not be used directly.  This method is called internally
956      * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
957      * {@link #remove}, or {@link #update} events fire.
958      * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
959      * @param {Record/Record[]} rs
960      * @param {Object} options
961      * @throws Error
962      * @private
963      */
964     execute : function(action, rs, options, /* private */ batch) {
965         // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
966         if (!Ext.data.Api.isAction(action)) {
967             throw new Ext.data.Api.Error('execute', action);
968         }
969         // make sure options has a fresh, new params hash
970         options = Ext.applyIf(options||{}, {
971             params: {}
972         });
973         if(batch !== undefined){
974             this.addToBatch(batch);
975         }
976         // have to separate before-events since load has a different signature than create,destroy and save events since load does not
977         // include the rs (record resultset) parameter.  Capture return values from the beforeaction into doRequest flag.
978         var doRequest = true;
979
980         if (action === 'read') {
981             doRequest = this.fireEvent('beforeload', this, options);
982             Ext.applyIf(options.params, this.baseParams);
983         }
984         else {
985             // if Writer is configured as listful, force single-record rs to be [{}] instead of {}
986             // TODO Move listful rendering into DataWriter where the @cfg is defined.  Should be easy now.
987             if (this.writer.listful === true && this.restful !== true) {
988                 rs = (Ext.isArray(rs)) ? rs : [rs];
989             }
990             // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
991             else if (Ext.isArray(rs) && rs.length == 1) {
992                 rs = rs.shift();
993             }
994             // Write the action to options.params
995             if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
996                 this.writer.apply(options.params, this.baseParams, action, rs);
997             }
998         }
999         if (doRequest !== false) {
1000             // Send request to proxy.
1001             if (this.writer && this.proxy.url && !this.proxy.restful && !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
1002                 options.params.xaction = action;    // <-- really old, probaby unecessary.
1003             }
1004             // Note:  Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions.
1005             // We'll flip it now and send the value into DataProxy#request, since it's the value which maps to
1006             // the user's configured DataProxy#api
1007             // TODO Refactor all Proxies to accept an instance of Ext.data.Request (not yet defined) instead of this looooooong list
1008             // of params.  This method is an artifact from Ext2.
1009             this.proxy.request(Ext.data.Api.actions[action], rs, options.params, this.reader, this.createCallback(action, rs, batch), this, options);
1010         }
1011         return doRequest;
1012     },
1013
1014     <div id="method-Ext.data.Store-save"></div>/**
1015      * Saves all pending changes to the store.  If the commensurate Ext.data.Api.actions action is not configured, then
1016      * the configured <code>{@link #url}</code> will be used.
1017      * <pre>
1018      * change            url
1019      * ---------------   --------------------
1020      * removed records   Ext.data.Api.actions.destroy
1021      * phantom records   Ext.data.Api.actions.create
1022      * {@link #getModifiedRecords modified records}  Ext.data.Api.actions.update
1023      * </pre>
1024      * @TODO:  Create extensions of Error class and send associated Record with thrown exceptions.
1025      * e.g.:  Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
1026      * @return {Number} batch Returns a number to uniquely identify the "batch" of saves occurring. -1 will be returned
1027      * if there are no items to save or the save was cancelled.
1028      */
1029     save : function() {
1030         if (!this.writer) {
1031             throw new Ext.data.Store.Error('writer-undefined');
1032         }
1033
1034         var queue = [],
1035             len,
1036             trans,
1037             batch,
1038             data = {},
1039             i;
1040         // DESTROY:  First check for removed records.  Records in this.removed are guaranteed non-phantoms.  @see Store#remove
1041         if(this.removed.length){
1042             queue.push(['destroy', this.removed]);
1043         }
1044
1045         // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
1046         var rs = [].concat(this.getModifiedRecords());
1047         if(rs.length){
1048             // CREATE:  Next check for phantoms within rs.  splice-off and execute create.
1049             var phantoms = [];
1050             for(i = rs.length-1; i >= 0; i--){
1051                 if(rs[i].phantom === true){
1052                     var rec = rs.splice(i, 1).shift();
1053                     if(rec.isValid()){
1054                         phantoms.push(rec);
1055                     }
1056                 }else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
1057                     rs.splice(i,1);
1058                 }
1059             }
1060             // If we have valid phantoms, create them...
1061             if(phantoms.length){
1062                 queue.push(['create', phantoms]);
1063             }
1064
1065             // UPDATE:  And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
1066             if(rs.length){
1067                 queue.push(['update', rs]);
1068             }
1069         }
1070         len = queue.length;
1071         if(len){
1072             batch = ++this.batchCounter;
1073             for(i = 0; i < len; ++i){
1074                 trans = queue[i];
1075                 data[trans[0]] = trans[1];
1076             }
1077             if(this.fireEvent('beforesave', this, data) !== false){
1078                 for(i = 0; i < len; ++i){
1079                     trans = queue[i];
1080                     this.doTransaction(trans[0], trans[1], batch);
1081                 }
1082                 return batch;
1083             }
1084         }
1085         return -1;
1086     },
1087
1088     // private.  Simply wraps call to Store#execute in try/catch.  Defers to Store#handleException on error.  Loops if batch: false
1089     doTransaction : function(action, rs, batch) {
1090         function transaction(records) {
1091             try{
1092                 this.execute(action, records, undefined, batch);
1093             }catch (e){
1094                 this.handleException(e);
1095             }
1096         }
1097         if(this.batch === false){
1098             for(var i = 0, len = rs.length; i < len; i++){
1099                 transaction.call(this, rs[i]);
1100             }
1101         }else{
1102             transaction.call(this, rs);
1103         }
1104     },
1105
1106     // private
1107     addToBatch : function(batch){
1108         var b = this.batches,
1109             key = this.batchKey + batch,
1110             o = b[key];
1111
1112         if(!o){
1113             b[key] = o = {
1114                 id: batch,
1115                 count: 0,
1116                 data: {}
1117             };
1118         }
1119         ++o.count;
1120     },
1121
1122     removeFromBatch : function(batch, action, data){
1123         var b = this.batches,
1124             key = this.batchKey + batch,
1125             o = b[key],
1126             arr;
1127
1128
1129         if(o){
1130             arr = o.data[action] || [];
1131             o.data[action] = arr.concat(data);
1132             if(o.count === 1){
1133                 data = o.data;
1134                 delete b[key];
1135                 this.fireEvent('save', this, batch, data);
1136             }else{
1137                 --o.count;
1138             }
1139         }
1140     },
1141
1142     // @private callback-handler for remote CRUD actions
1143     // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
1144     createCallback : function(action, rs, batch) {
1145         var actions = Ext.data.Api.actions;
1146         return (action == 'read') ? this.loadRecords : function(data, response, success) {
1147             // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
1148             this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, [].concat(data));
1149             // If success === false here, exception will have been called in DataProxy
1150             if (success === true) {
1151                 this.fireEvent('write', this, action, data, response, rs);
1152             }
1153             this.removeFromBatch(batch, action, data);
1154         };
1155     },
1156
1157     // Clears records from modified array after an exception event.
1158     // NOTE:  records are left marked dirty.  Do we want to commit them even though they were not updated/realized?
1159     // TODO remove this method?
1160     clearModified : function(rs) {
1161         if (Ext.isArray(rs)) {
1162             for (var n=rs.length-1;n>=0;n--) {
1163                 this.modified.splice(this.modified.indexOf(rs[n]), 1);
1164             }
1165         } else {
1166             this.modified.splice(this.modified.indexOf(rs), 1);
1167         }
1168     },
1169
1170     // remap record ids in MixedCollection after records have been realized.  @see Store#onCreateRecords, @see DataReader#realize
1171     reMap : function(record) {
1172         if (Ext.isArray(record)) {
1173             for (var i = 0, len = record.length; i < len; i++) {
1174                 this.reMap(record[i]);
1175             }
1176         } else {
1177             delete this.data.map[record._phid];
1178             this.data.map[record.id] = record;
1179             var index = this.data.keys.indexOf(record._phid);
1180             this.data.keys.splice(index, 1, record.id);
1181             delete record._phid;
1182         }
1183     },
1184
1185     // @protected onCreateRecord proxy callback for create action
1186     onCreateRecords : function(success, rs, data) {
1187         if (success === true) {
1188             try {
1189                 this.reader.realize(rs, data);
1190                 this.reMap(rs);
1191             }
1192             catch (e) {
1193                 this.handleException(e);
1194                 if (Ext.isArray(rs)) {
1195                     // Recurse to run back into the try {}.  DataReader#realize splices-off the rs until empty.
1196                     this.onCreateRecords(success, rs, data);
1197                 }
1198             }
1199         }
1200     },
1201
1202     // @protected, onUpdateRecords proxy callback for update action
1203     onUpdateRecords : function(success, rs, data) {
1204         if (success === true) {
1205             try {
1206                 this.reader.update(rs, data);
1207             } catch (e) {
1208                 this.handleException(e);
1209                 if (Ext.isArray(rs)) {
1210                     // Recurse to run back into the try {}.  DataReader#update splices-off the rs until empty.
1211                     this.onUpdateRecords(success, rs, data);
1212                 }
1213             }
1214         }
1215     },
1216
1217     // @protected onDestroyRecords proxy callback for destroy action
1218     onDestroyRecords : function(success, rs, data) {
1219         // splice each rec out of this.removed
1220         rs = (rs instanceof Ext.data.Record) ? [rs] : [].concat(rs);
1221         for (var i=0,len=rs.length;i<len;i++) {
1222             this.removed.splice(this.removed.indexOf(rs[i]), 1);
1223         }
1224         if (success === false) {
1225             // put records back into store if remote destroy fails.
1226             // @TODO: Might want to let developer decide.
1227             for (i=rs.length-1;i>=0;i--) {
1228                 this.insert(rs[i].lastIndex, rs[i]);    // <-- lastIndex set in Store#destroyRecord
1229             }
1230         }
1231     },
1232
1233     // protected handleException.  Possibly temporary until Ext framework has an exception-handler.
1234     handleException : function(e) {
1235         // @see core/Error.js
1236         Ext.handleError(e);
1237     },
1238
1239     <div id="method-Ext.data.Store-reload"></div>/**
1240      * <p>Reloads the Record cache from the configured Proxy using the configured
1241      * {@link Ext.data.Reader Reader} and the options from the last load operation
1242      * performed.</p>
1243      * <p><b>Note</b>: see the Important note in {@link #load}.</p>
1244      * @param {Object} options <p>(optional) An <tt>Object</tt> containing
1245      * {@link #load loading options} which may override the {@link #lastOptions options}
1246      * used in the last {@link #load} operation. See {@link #load} for details
1247      * (defaults to <tt>null</tt>, in which case the {@link #lastOptions} are
1248      * used).</p>
1249      * <br><p>To add new params to the existing params:</p><pre><code>
1250 lastOptions = myStore.lastOptions;
1251 Ext.apply(lastOptions.params, {
1252     myNewParam: true
1253 });
1254 myStore.reload(lastOptions);
1255      * </code></pre>
1256      */
1257     reload : function(options){
1258         this.load(Ext.applyIf(options||{}, this.lastOptions));
1259     },
1260
1261     // private
1262     // Called as a callback by the Reader during a load operation.
1263     loadRecords : function(o, options, success){
1264         var i, len;
1265         
1266         if (this.isDestroyed === true) {
1267             return;
1268         }
1269         if(!o || success === false){
1270             if(success !== false){
1271                 this.fireEvent('load', this, [], options);
1272             }
1273             if(options.callback){
1274                 options.callback.call(options.scope || this, [], options, false, o);
1275             }
1276             return;
1277         }
1278         var r = o.records, t = o.totalRecords || r.length;
1279         if(!options || options.add !== true){
1280             if(this.pruneModifiedRecords){
1281                 this.modified = [];
1282             }
1283             for(i = 0, len = r.length; i < len; i++){
1284                 r[i].join(this);
1285             }
1286             if(this.snapshot){
1287                 this.data = this.snapshot;
1288                 delete this.snapshot;
1289             }
1290             this.clearData();
1291             this.data.addAll(r);
1292             this.totalLength = t;
1293             this.applySort();
1294             this.fireEvent('datachanged', this);
1295         }else{
1296             var toAdd = [],
1297                 rec,
1298                 cnt = 0;
1299             for(i = 0, len = r.length; i < len; ++i){
1300                 rec = r[i];
1301                 if(this.indexOfId(rec.id) > -1){
1302                     this.doUpdate(rec);
1303                 }else{
1304                     toAdd.push(rec);
1305                     ++cnt;
1306                 }
1307             }
1308             this.totalLength = Math.max(t, this.data.length + cnt);
1309             this.add(toAdd);
1310         }
1311         this.fireEvent('load', this, r, options);
1312         if(options.callback){
1313             options.callback.call(options.scope || this, r, options, true);
1314         }
1315     },
1316
1317     <div id="method-Ext.data.Store-loadData"></div>/**
1318      * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
1319      * which understands the format of the data must have been configured in the constructor.
1320      * @param {Object} data The data block from which to read the Records.  The format of the data expected
1321      * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
1322      * that {@link Ext.data.Reader Reader}'s <tt>{@link Ext.data.Reader#readRecords}</tt> parameter.
1323      * @param {Boolean} append (Optional) <tt>true</tt> to append the new Records rather the default to replace
1324      * the existing cache.
1325      * <b>Note</b>: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
1326      * with ids which are already present in the Store will <i>replace</i> existing Records. Only Records with
1327      * new, unique ids will be added.
1328      */
1329     loadData : function(o, append){
1330         var r = this.reader.readRecords(o);
1331         this.loadRecords(r, {add: append}, true);
1332     },
1333
1334     <div id="method-Ext.data.Store-getCount"></div>/**
1335      * Gets the number of cached records.
1336      * <p>If using paging, this may not be the total size of the dataset. If the data object
1337      * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
1338      * the dataset size.  <b>Note</b>: see the Important note in {@link #load}.</p>
1339      * @return {Number} The number of Records in the Store's cache.
1340      */
1341     getCount : function(){
1342         return this.data.length || 0;
1343     },
1344
1345     <div id="method-Ext.data.Store-getTotalCount"></div>/**
1346      * Gets the total number of records in the dataset as returned by the server.
1347      * <p>If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
1348      * must contain the dataset size. For remote data sources, the value for this property
1349      * (<tt>totalProperty</tt> for {@link Ext.data.JsonReader JsonReader},
1350      * <tt>totalRecords</tt> for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
1351      * <b>Note</b>: see the Important note in {@link #load}.</p>
1352      * @return {Number} The number of Records as specified in the data object passed to the Reader
1353      * by the Proxy.
1354      * <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
1355      */
1356     getTotalCount : function(){
1357         return this.totalLength || 0;
1358     },
1359
1360     <div id="method-Ext.data.Store-getSortState"></div>/**
1361      * Returns an object describing the current sort state of this Store.
1362      * @return {Object} The sort state of the Store. An object with two properties:<ul>
1363      * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>
1364      * <li><b>direction : String<p class="sub-desc">The sort order, 'ASC' or 'DESC' (case-sensitive).</p></li>
1365      * </ul>
1366      * See <tt>{@link #sortInfo}</tt> for additional details.
1367      */
1368     getSortState : function(){
1369         return this.sortInfo;
1370     },
1371
1372     /**
1373      * @private
1374      * Invokes sortData if we have sortInfo to sort on and are not sorting remotely
1375      */
1376     applySort : function(){
1377         if ((this.sortInfo || this.multiSortInfo) && !this.remoteSort) {
1378             this.sortData();
1379         }
1380     },
1381
1382     /**
1383      * @private
1384      * Performs the actual sorting of data. This checks to see if we currently have a multi sort or not. It applies
1385      * each sorter field/direction pair in turn by building an OR'ed master sorting function and running it against
1386      * the full dataset
1387      */
1388     sortData : function() {
1389         var sortInfo  = this.hasMultiSort ? this.multiSortInfo : this.sortInfo,
1390             direction = sortInfo.direction || "ASC",
1391             sorters   = sortInfo.sorters,
1392             sortFns   = [];
1393
1394         //if we just have a single sorter, pretend it's the first in an array
1395         if (!this.hasMultiSort) {
1396             sorters = [{direction: direction, field: sortInfo.field}];
1397         }
1398
1399         //create a sorter function for each sorter field/direction combo
1400         for (var i=0, j = sorters.length; i < j; i++) {
1401             sortFns.push(this.createSortFunction(sorters[i].field, sorters[i].direction));
1402         }
1403         
1404         if (sortFns.length == 0) {
1405             return;
1406         }
1407
1408         //the direction modifier is multiplied with the result of the sorting functions to provide overall sort direction
1409         //(as opposed to direction per field)
1410         var directionModifier = direction.toUpperCase() == "DESC" ? -1 : 1;
1411
1412         //create a function which ORs each sorter together to enable multi-sort
1413         var fn = function(r1, r2) {
1414           var result = sortFns[0].call(this, r1, r2);
1415
1416           //if we have more than one sorter, OR any additional sorter functions together
1417           if (sortFns.length > 1) {
1418               for (var i=1, j = sortFns.length; i < j; i++) {
1419                   result = result || sortFns[i].call(this, r1, r2);
1420               }
1421           }
1422
1423           return directionModifier * result;
1424         };
1425
1426         //sort the data
1427         this.data.sort(direction, fn);
1428         if (this.snapshot && this.snapshot != this.data) {
1429             this.snapshot.sort(direction, fn);
1430         }
1431     },
1432
1433     /**
1434      * @private
1435      * Creates and returns a function which sorts an array by the given field and direction
1436      * @param {String} field The field to create the sorter for
1437      * @param {String} direction The direction to sort by (defaults to "ASC")
1438      * @return {Function} A function which sorts by the field/direction combination provided
1439      */
1440     createSortFunction: function(field, direction) {
1441         direction = direction || "ASC";
1442         var directionModifier = direction.toUpperCase() == "DESC" ? -1 : 1;
1443
1444         var sortType = this.fields.get(field).sortType;
1445
1446         //create a comparison function. Takes 2 records, returns 1 if record 1 is greater,
1447         //-1 if record 2 is greater or 0 if they are equal
1448         return function(r1, r2) {
1449             var v1 = sortType(r1.data[field]),
1450                 v2 = sortType(r2.data[field]);
1451
1452             return directionModifier * (v1 > v2 ? 1 : (v1 < v2 ? -1 : 0));
1453         };
1454     },
1455
1456     <div id="method-Ext.data.Store-setDefaultSort"></div>/**
1457      * Sets the default sort column and order to be used by the next {@link #load} operation.
1458      * @param {String} fieldName The name of the field to sort by.
1459      * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1460      */
1461     setDefaultSort : function(field, dir) {
1462         dir = dir ? dir.toUpperCase() : 'ASC';
1463         this.sortInfo = {field: field, direction: dir};
1464         this.sortToggle[field] = dir;
1465     },
1466
1467     <div id="method-Ext.data.Store-sort"></div>/**
1468      * Sort the Records.
1469      * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
1470      * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
1471      * This function accepts two call signatures - pass in a field name as the first argument to sort on a single
1472      * field, or pass in an array of sort configuration objects to sort by multiple fields.
1473      * Single sort example:
1474      * store.sort('name', 'ASC');
1475      * Multi sort example:
1476      * store.sort([
1477      *   {
1478      *     field    : 'name',
1479      *     direction: 'ASC'
1480      *   },
1481      *   {
1482      *     field    : 'salary',
1483      *     direction: 'DESC'
1484      *   }
1485      * ], 'ASC');
1486      * In this second form, the sort configs are applied in order, with later sorters sorting within earlier sorters' results.
1487      * For example, if two records with the same name are present they will also be sorted by salary if given the sort configs
1488      * above. Any number of sort configs can be added.
1489      * @param {String/Array} fieldName The name of the field to sort by, or an array of ordered sort configs
1490      * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1491      */
1492     sort : function(fieldName, dir) {
1493         if (Ext.isArray(arguments[0])) {
1494             return this.multiSort.call(this, fieldName, dir);
1495         } else {
1496             return this.singleSort(fieldName, dir);
1497         }
1498     },
1499
1500     <div id="method-Ext.data.Store-singleSort"></div>/**
1501      * Sorts the store contents by a single field and direction. This is called internally by {@link sort} and would
1502      * not usually be called manually
1503      * @param {String} fieldName The name of the field to sort by.
1504      * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
1505      */
1506     singleSort: function(fieldName, dir) {
1507         var field = this.fields.get(fieldName);
1508         if (!field) {
1509             return false;
1510         }
1511
1512         var name       = field.name,
1513             sortInfo   = this.sortInfo || null,
1514             sortToggle = this.sortToggle ? this.sortToggle[name] : null;
1515
1516         if (!dir) {
1517             if (sortInfo && sortInfo.field == name) { // toggle sort dir
1518                 dir = (this.sortToggle[name] || 'ASC').toggle('ASC', 'DESC');
1519             } else {
1520                 dir = field.sortDir;
1521             }
1522         }
1523
1524         this.sortToggle[name] = dir;
1525         this.sortInfo = {field: name, direction: dir};
1526         this.hasMultiSort = false;
1527
1528         if (this.remoteSort) {
1529             if (!this.load(this.lastOptions)) {
1530                 if (sortToggle) {
1531                     this.sortToggle[name] = sortToggle;
1532                 }
1533                 if (sortInfo) {
1534                     this.sortInfo = sortInfo;
1535                 }
1536             }
1537         } else {
1538             this.applySort();
1539             this.fireEvent('datachanged', this);
1540         }
1541         return true;
1542     },
1543
1544     <div id="method-Ext.data.Store-multiSort"></div>/**
1545      * Sorts the contents of this store by multiple field/direction sorters. This is called internally by {@link sort}
1546      * and would not usually be called manually.
1547      * Multi sorting only currently applies to local datasets - multiple sort data is not currently sent to a proxy
1548      * if remoteSort is used.
1549      * @param {Array} sorters Array of sorter objects (field and direction)
1550      * @param {String} direction Overall direction to sort the ordered results by (defaults to "ASC")
1551      */
1552     multiSort: function(sorters, direction) {
1553         this.hasMultiSort = true;
1554         direction = direction || "ASC";
1555
1556         //toggle sort direction
1557         if (this.multiSortInfo && direction == this.multiSortInfo.direction) {
1558             direction = direction.toggle("ASC", "DESC");
1559         }
1560
1561         <div id="prop-Ext.data.Store-multiSortInfo"></div>/**
1562          * Object containing overall sort direction and an ordered array of sorter configs used when sorting on multiple fields
1563          * @property multiSortInfo
1564          * @type Object
1565          */
1566         this.multiSortInfo = {
1567             sorters  : sorters,
1568             direction: direction
1569         };
1570         
1571         if (this.remoteSort) {
1572             this.singleSort(sorters[0].field, sorters[0].direction);
1573
1574         } else {
1575             this.applySort();
1576             this.fireEvent('datachanged', this);
1577         }
1578     },
1579
1580     <div id="method-Ext.data.Store-each"></div>/**
1581      * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
1582      * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
1583      * Returning <tt>false</tt> aborts and exits the iteration.
1584      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed.
1585      * Defaults to the current {@link Ext.data.Record Record} in the iteration.
1586      */
1587     each : function(fn, scope){
1588         this.data.each(fn, scope);
1589     },
1590
1591     <div id="method-Ext.data.Store-getModifiedRecords"></div>/**
1592      * Gets all {@link Ext.data.Record records} modified since the last commit.  Modified records are
1593      * persisted across load operations (e.g., during paging). <b>Note</b>: deleted records are not
1594      * included.  See also <tt>{@link #pruneModifiedRecords}</tt> and
1595      * {@link Ext.data.Record}<tt>{@link Ext.data.Record#markDirty markDirty}.</tt>.
1596      * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
1597      * modifications.  To obtain modified fields within a modified record see
1598      *{@link Ext.data.Record}<tt>{@link Ext.data.Record#modified modified}.</tt>.
1599      */
1600     getModifiedRecords : function(){
1601         return this.modified;
1602     },
1603
1604     <div id="method-Ext.data.Store-sum"></div>/**
1605      * Sums the value of <tt>property</tt> for each {@link Ext.data.Record record} between <tt>start</tt>
1606      * and <tt>end</tt> and returns the result.
1607      * @param {String} property A field in each record
1608      * @param {Number} start (optional) The record index to start at (defaults to <tt>0</tt>)
1609      * @param {Number} end (optional) The last record index to include (defaults to length - 1)
1610      * @return {Number} The sum
1611      */
1612     sum : function(property, start, end){
1613         var rs = this.data.items, v = 0;
1614         start = start || 0;
1615         end = (end || end === 0) ? end : rs.length-1;
1616
1617         for(var i = start; i <= end; i++){
1618             v += (rs[i].data[property] || 0);
1619         }
1620         return v;
1621     },
1622
1623     /**
1624      * @private
1625      * Returns a filter function used to test a the given property's value. Defers most of the work to
1626      * Ext.util.MixedCollection's createValueMatcher function
1627      * @param {String} property The property to create the filter function for
1628      * @param {String/RegExp} value The string/regex to compare the property value to
1629      * @param {Boolean} anyMatch True if we don't care if the filter value is not the full value (defaults to false)
1630      * @param {Boolean} caseSensitive True to create a case-sensitive regex (defaults to false)
1631      * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
1632      */
1633     createFilterFn : function(property, value, anyMatch, caseSensitive, exactMatch){
1634         if(Ext.isEmpty(value, false)){
1635             return false;
1636         }
1637         value = this.data.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
1638         return function(r) {
1639             return value.test(r.data[property]);
1640         };
1641     },
1642
1643     /**
1644      * @private
1645      * Given an array of filter functions (each with optional scope), constructs and returns a single function that returns
1646      * the result of all of the filters ANDed together
1647      * @param {Array} filters The array of filter objects (each object should contain an 'fn' and optional scope)
1648      * @return {Function} The multiple filter function
1649      */
1650     createMultipleFilterFn: function(filters) {
1651         return function(record) {
1652             var isMatch = true;
1653
1654             for (var i=0, j = filters.length; i < j; i++) {
1655                 var filter = filters[i],
1656                     fn     = filter.fn,
1657                     scope  = filter.scope;
1658
1659                 isMatch = isMatch && fn.call(scope, record);
1660             }
1661
1662             return isMatch;
1663         };
1664     },
1665
1666     <div id="method-Ext.data.Store-filter"></div>/**
1667      * Filter the {@link Ext.data.Record records} by a specified property. Alternatively, pass an array of filter
1668      * options to filter by more than one property.
1669      * Single filter example:
1670      * store.filter('name', 'Ed', true, true); //finds all records containing the substring 'Ed'
1671      * Multiple filter example:
1672      * <pre><code>
1673      * store.filter([
1674      *   {
1675      *     property     : 'name',
1676      *     value        : 'Ed',
1677      *     anyMatch     : true, //optional, defaults to true
1678      *     caseSensitive: true  //optional, defaults to true
1679      *   },
1680      *
1681      *   //filter functions can also be passed
1682      *   {
1683      *     fn   : function(record) {
1684      *       return record.get('age') == 24
1685      *     },
1686      *     scope: this
1687      *   }
1688      * ]);
1689      * </code></pre>
1690      * @param {String|Array} field A field on your records, or an array containing multiple filter options
1691      * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
1692      * against the field.
1693      * @param {Boolean} anyMatch (optional) <tt>true</tt> to match any part not just the beginning
1694      * @param {Boolean} caseSensitive (optional) <tt>true</tt> for case sensitive comparison
1695      * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
1696      */
1697     filter : function(property, value, anyMatch, caseSensitive, exactMatch){
1698         var fn;
1699         //we can accept an array of filter objects, or a single filter object - normalize them here
1700         if (Ext.isObject(property)) {
1701             property = [property];
1702         }
1703
1704         if (Ext.isArray(property)) {
1705             var filters = [];
1706
1707             //normalize the filters passed into an array of filter functions
1708             for (var i=0, j = property.length; i < j; i++) {
1709                 var filter = property[i],
1710                     func   = filter.fn,
1711                     scope  = filter.scope || this;
1712
1713                 //if we weren't given a filter function, construct one now
1714                 if (!Ext.isFunction(func)) {
1715                     func = this.createFilterFn(filter.property, filter.value, filter.anyMatch, filter.caseSensitive, filter.exactMatch);
1716                 }
1717
1718                 filters.push({fn: func, scope: scope});
1719             }
1720
1721             fn = this.createMultipleFilterFn(filters);
1722         } else {
1723             //classic single property filter
1724             fn = this.createFilterFn(property, value, anyMatch, caseSensitive, exactMatch);
1725         }
1726
1727         return fn ? this.filterBy(fn) : this.clearFilter();
1728     },
1729
1730     <div id="method-Ext.data.Store-filterBy"></div>/**
1731      * Filter by a function. The specified function will be called for each
1732      * Record in this Store. If the function returns <tt>true</tt> the Record is included,
1733      * otherwise it is filtered out.
1734      * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1735      * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1736      * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1737      * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1738      * </ul>
1739      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1740      */
1741     filterBy : function(fn, scope){
1742         this.snapshot = this.snapshot || this.data;
1743         this.data = this.queryBy(fn, scope || this);
1744         this.fireEvent('datachanged', this);
1745     },
1746
1747     <div id="method-Ext.data.Store-clearFilter"></div>/**
1748      * Revert to a view of the Record cache with no filtering applied.
1749      * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
1750      * {@link #datachanged} event.
1751      */
1752     clearFilter : function(suppressEvent){
1753         if(this.isFiltered()){
1754             this.data = this.snapshot;
1755             delete this.snapshot;
1756             if(suppressEvent !== true){
1757                 this.fireEvent('datachanged', this);
1758             }
1759         }
1760     },
1761
1762     <div id="method-Ext.data.Store-isFiltered"></div>/**
1763      * Returns true if this store is currently filtered
1764      * @return {Boolean}
1765      */
1766     isFiltered : function(){
1767         return !!this.snapshot && this.snapshot != this.data;
1768     },
1769
1770     <div id="method-Ext.data.Store-query"></div>/**
1771      * Query the records by a specified property.
1772      * @param {String} field A field on your records
1773      * @param {String/RegExp} value Either a string that the field
1774      * should begin with, or a RegExp to test against the field.
1775      * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
1776      * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1777      * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1778      */
1779     query : function(property, value, anyMatch, caseSensitive){
1780         var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1781         return fn ? this.queryBy(fn) : this.data.clone();
1782     },
1783
1784     <div id="method-Ext.data.Store-queryBy"></div>/**
1785      * Query the cached records in this Store using a filtering function. The specified function
1786      * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
1787      * included in the results.
1788      * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1789      * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1790      * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1791      * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1792      * </ul>
1793      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1794      * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
1795      **/
1796     queryBy : function(fn, scope){
1797         var data = this.snapshot || this.data;
1798         return data.filterBy(fn, scope||this);
1799     },
1800
1801     <div id="method-Ext.data.Store-find"></div>/**
1802      * Finds the index of the first matching Record in this store by a specific field value.
1803      * @param {String} fieldName The name of the Record field to test.
1804      * @param {String/RegExp} value Either a string that the field value
1805      * should begin with, or a RegExp to test against the field.
1806      * @param {Number} startIndex (optional) The index to start searching at
1807      * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
1808      * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
1809      * @return {Number} The matched index or -1
1810      */
1811     find : function(property, value, start, anyMatch, caseSensitive){
1812         var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
1813         return fn ? this.data.findIndexBy(fn, null, start) : -1;
1814     },
1815
1816     <div id="method-Ext.data.Store-findExact"></div>/**
1817      * Finds the index of the first matching Record in this store by a specific field value.
1818      * @param {String} fieldName The name of the Record field to test.
1819      * @param {Mixed} value The value to match the field against.
1820      * @param {Number} startIndex (optional) The index to start searching at
1821      * @return {Number} The matched index or -1
1822      */
1823     findExact: function(property, value, start){
1824         return this.data.findIndexBy(function(rec){
1825             return rec.get(property) === value;
1826         }, this, start);
1827     },
1828
1829     <div id="method-Ext.data.Store-findBy"></div>/**
1830      * Find the index of the first matching Record in this Store by a function.
1831      * If the function returns <tt>true</tt> it is considered a match.
1832      * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
1833      * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
1834      * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
1835      * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
1836      * </ul>
1837      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
1838      * @param {Number} startIndex (optional) The index to start searching at
1839      * @return {Number} The matched index or -1
1840      */
1841     findBy : function(fn, scope, start){
1842         return this.data.findIndexBy(fn, scope, start);
1843     },
1844
1845     <div id="method-Ext.data.Store-collect"></div>/**
1846      * Collects unique values for a particular dataIndex from this store.
1847      * @param {String} dataIndex The property to collect
1848      * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
1849      * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
1850      * @return {Array} An array of the unique values
1851      **/
1852     collect : function(dataIndex, allowNull, bypassFilter){
1853         var d = (bypassFilter === true && this.snapshot) ?
1854                 this.snapshot.items : this.data.items;
1855         var v, sv, r = [], l = {};
1856         for(var i = 0, len = d.length; i < len; i++){
1857             v = d[i].data[dataIndex];
1858             sv = String(v);
1859             if((allowNull || !Ext.isEmpty(v)) && !l[sv]){
1860                 l[sv] = true;
1861                 r[r.length] = v;
1862             }
1863         }
1864         return r;
1865     },
1866
1867     // private
1868     afterEdit : function(record){
1869         if(this.modified.indexOf(record) == -1){
1870             this.modified.push(record);
1871         }
1872         this.fireEvent('update', this, record, Ext.data.Record.EDIT);
1873     },
1874
1875     // private
1876     afterReject : function(record){
1877         this.modified.remove(record);
1878         this.fireEvent('update', this, record, Ext.data.Record.REJECT);
1879     },
1880
1881     // private
1882     afterCommit : function(record){
1883         this.modified.remove(record);
1884         this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
1885     },
1886
1887     <div id="method-Ext.data.Store-commitChanges"></div>/**
1888      * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
1889      * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
1890      * Ext.data.Record.COMMIT.
1891      */
1892     commitChanges : function(){
1893         var modified = this.modified.slice(0),
1894             length   = modified.length,
1895             i;
1896             
1897         for (i = 0; i < length; i++){
1898             modified[i].commit();
1899         }
1900         
1901         this.modified = [];
1902         this.removed  = [];
1903     },
1904
1905     <div id="method-Ext.data.Store-rejectChanges"></div>/**
1906      * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
1907      */
1908     rejectChanges : function() {
1909         var modified = this.modified.slice(0),
1910             removed  = this.removed.slice(0).reverse(),
1911             mLength  = modified.length,
1912             rLength  = removed.length,
1913             i;
1914         
1915         for (i = 0; i < mLength; i++) {
1916             modified[i].reject();
1917         }
1918         
1919         for (i = 0; i < rLength; i++) {
1920             this.insert(removed[i].lastIndex || 0, removed[i]);
1921             removed[i].reject();
1922         }
1923         
1924         this.modified = [];
1925         this.removed  = [];
1926     },
1927
1928     // private
1929     onMetaChange : function(meta){
1930         this.recordType = this.reader.recordType;
1931         this.fields = this.recordType.prototype.fields;
1932         delete this.snapshot;
1933         if(this.reader.meta.sortInfo){
1934             this.sortInfo = this.reader.meta.sortInfo;
1935         }else if(this.sortInfo  && !this.fields.get(this.sortInfo.field)){
1936             delete this.sortInfo;
1937         }
1938         if(this.writer){
1939             this.writer.meta = this.reader.meta;
1940         }
1941         this.modified = [];
1942         this.fireEvent('metachange', this, this.reader.meta);
1943     },
1944
1945     // private
1946     findInsertIndex : function(record){
1947         this.suspendEvents();
1948         var data = this.data.clone();
1949         this.data.add(record);
1950         this.applySort();
1951         var index = this.data.indexOf(record);
1952         this.data = data;
1953         this.resumeEvents();
1954         return index;
1955     },
1956
1957     <div id="method-Ext.data.Store-setBaseParam"></div>/**
1958      * Set the value for a property name in this store's {@link #baseParams}.  Usage:</p><pre><code>
1959 myStore.setBaseParam('foo', {bar:3});
1960 </code></pre>
1961      * @param {String} name Name of the property to assign
1962      * @param {Mixed} value Value to assign the <tt>name</tt>d property
1963      **/
1964     setBaseParam : function (name, value){
1965         this.baseParams = this.baseParams || {};
1966         this.baseParams[name] = value;
1967     }
1968 });
1969
1970 Ext.reg('store', Ext.data.Store);
1971
1972 <div id="cls-Ext.data.Store.Error"></div>/**
1973  * @class Ext.data.Store.Error
1974  * @extends Ext.Error
1975  * Store Error extension.
1976  * @param {String} name
1977  */
1978 Ext.data.Store.Error = Ext.extend(Ext.Error, {
1979     name: 'Ext.data.Store'
1980 });
1981 Ext.apply(Ext.data.Store.Error.prototype, {
1982     lang: {
1983         'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'
1984     }
1985 });
1986 </pre>    
1987 </body>
1988 </html>