Roo/data/Store.js
[roojs1] / Roo / data / Store.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11
12
13
14 /**
15  * @class Roo.data.Store
16  * @extends Roo.util.Observable
17  * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
18  * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
19  * <p>
20  * A Store object uses an implementation of {@link Roo.data.DataProxy} to access a data object unless you call loadData() directly and pass in your data. The Store object
21  * has no knowledge of the format of the data returned by the Proxy.<br>
22  * <p>
23  * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
24  * instances from the data object. These records are cached and made available through accessor functions.
25  * @constructor
26  * Creates a new Store.
27  * @param {Object} config A config object containing the objects needed for the Store to access data,
28  * and read the data into Records.
29  */
30 Roo.data.Store = function(config){
31     this.data = new Roo.util.MixedCollection(false);
32     this.data.getKey = function(o){
33         return o.id;
34     };
35     this.baseParams = {};
36     // private
37     this.paramNames = {
38         "start" : "start",
39         "limit" : "limit",
40         "sort" : "sort",
41         "dir" : "dir",
42         "multisort" : "_multisort"
43     };
44
45     if(config && config.data){
46         this.inlineData = config.data;
47         delete config.data;
48     }
49
50     Roo.apply(this, config);
51     
52     if(this.reader){ // reader passed
53         this.reader = Roo.factory(this.reader, Roo.data);
54         this.reader.xmodule = this.xmodule || false;
55         if(!this.recordType){
56             this.recordType = this.reader.recordType;
57         }
58         if(this.reader.onMetaChange){
59             this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
60         }
61     }
62
63     if(this.recordType){
64         this.fields = this.recordType.prototype.fields;
65     }
66     this.modified = [];
67
68     this.addEvents({
69         /**
70          * @event datachanged
71          * Fires when the data cache has changed, and a widget which is using this Store
72          * as a Record cache should refresh its view.
73          * @param {Store} this
74          */
75         datachanged : true,
76         /**
77          * @event metachange
78          * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
79          * @param {Store} this
80          * @param {Object} meta The JSON metadata
81          */
82         metachange : true,
83         /**
84          * @event add
85          * Fires when Records have been added to the Store
86          * @param {Store} this
87          * @param {Roo.data.Record[]} records The array of Records added
88          * @param {Number} index The index at which the record(s) were added
89          */
90         add : true,
91         /**
92          * @event remove
93          * Fires when a Record has been removed from the Store
94          * @param {Store} this
95          * @param {Roo.data.Record} record The Record that was removed
96          * @param {Number} index The index at which the record was removed
97          */
98         remove : true,
99         /**
100          * @event update
101          * Fires when a Record has been updated
102          * @param {Store} this
103          * @param {Roo.data.Record} record The Record that was updated
104          * @param {String} operation The update operation being performed.  Value may be one of:
105          * <pre><code>
106  Roo.data.Record.EDIT
107  Roo.data.Record.REJECT
108  Roo.data.Record.COMMIT
109          * </code></pre>
110          */
111         update : true,
112         /**
113          * @event clear
114          * Fires when the data cache has been cleared.
115          * @param {Store} this
116          */
117         clear : true,
118         /**
119          * @event beforeload
120          * Fires before a request is made for a new data object.  If the beforeload handler returns false
121          * the load action will be canceled.
122          * @param {Store} this
123          * @param {Object} options The loading options that were specified (see {@link #load} for details)
124          */
125         beforeload : true,
126         /**
127          * @event beforeloadadd
128          * Fires after a new set of Records has been loaded.
129          * @param {Store} this
130          * @param {Roo.data.Record[]} records The Records that were loaded
131          * @param {Object} options The loading options that were specified (see {@link #load} for details)
132          */
133         beforeloadadd : true,
134         /**
135          * @event load
136          * Fires after a new set of Records has been loaded, before they are added to the store.
137          * @param {Store} this
138          * @param {Roo.data.Record[]} records The Records that were loaded
139          * @param {Object} options The loading options that were specified (see {@link #load} for details)
140          * @params {Object} return from reader
141          */
142         load : true,
143         /**
144          * @event loadexception
145          * Fires if an exception occurs in the Proxy during loading.
146          * Called with the signature of the Proxy's "loadexception" event.
147          * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
148          * 
149          * @param {Proxy} 
150          * @param {Object} return from JsonData.reader() - success, totalRecords, records
151          * @param {Object} load options 
152          * @param {Object} jsonData from your request (normally this contains the Exception)
153          */
154         loadexception : true
155     });
156     
157     if(this.proxy){
158         this.proxy = Roo.factory(this.proxy, Roo.data);
159         this.proxy.xmodule = this.xmodule || false;
160         this.relayEvents(this.proxy,  ["loadexception"]);
161     }
162     this.sortToggle = {};
163     this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
164
165     Roo.data.Store.superclass.constructor.call(this);
166
167     if(this.inlineData){
168         this.loadData(this.inlineData);
169         delete this.inlineData;
170     }
171 };
172
173 Roo.extend(Roo.data.Store, Roo.util.Observable, {
174      /**
175     * @cfg {boolean} isLocal   flag if data is locally available (and can be always looked up
176     * without a remote query - used by combo/forms at present.
177     */
178     
179     /**
180     * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
181     */
182     /**
183     * @cfg {Array} data Inline data to be loaded when the store is initialized.
184     */
185     /**
186     * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
187     * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
188     */
189     /**
190     * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
191     * on any HTTP request
192     */
193     /**
194     * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
195     */
196     /**
197     * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
198     */
199     multiSort: false,
200     /**
201     * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
202     * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
203     */
204     remoteSort : false,
205
206     /**
207     * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
208      * loaded or when a record is removed. (defaults to false).
209     */
210     pruneModifiedRecords : false,
211
212     // private
213     lastOptions : null,
214
215     /**
216      * Add Records to the Store and fires the add event.
217      * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
218      */
219     add : function(records){
220         records = [].concat(records);
221         for(var i = 0, len = records.length; i < len; i++){
222             records[i].join(this);
223         }
224         var index = this.data.length;
225         this.data.addAll(records);
226         this.fireEvent("add", this, records, index);
227     },
228
229     /**
230      * Remove a Record from the Store and fires the remove event.
231      * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
232      */
233     remove : function(record){
234         var index = this.data.indexOf(record);
235         this.data.removeAt(index);
236         if(this.pruneModifiedRecords){
237             this.modified.remove(record);
238         }
239         this.fireEvent("remove", this, record, index);
240     },
241
242     /**
243      * Remove all Records from the Store and fires the clear event.
244      */
245     removeAll : function(){
246         this.data.clear();
247         if(this.pruneModifiedRecords){
248             this.modified = [];
249         }
250         this.fireEvent("clear", this);
251     },
252
253     /**
254      * Inserts Records to the Store at the given index and fires the add event.
255      * @param {Number} index The start index at which to insert the passed Records.
256      * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
257      */
258     insert : function(index, records){
259         records = [].concat(records);
260         for(var i = 0, len = records.length; i < len; i++){
261             this.data.insert(index, records[i]);
262             records[i].join(this);
263         }
264         this.fireEvent("add", this, records, index);
265     },
266
267     /**
268      * Get the index within the cache of the passed Record.
269      * @param {Roo.data.Record} record The Roo.data.Record object to to find.
270      * @return {Number} The index of the passed Record. Returns -1 if not found.
271      */
272     indexOf : function(record){
273         return this.data.indexOf(record);
274     },
275
276     /**
277      * Get the index within the cache of the Record with the passed id.
278      * @param {String} id The id of the Record to find.
279      * @return {Number} The index of the Record. Returns -1 if not found.
280      */
281     indexOfId : function(id){
282         return this.data.indexOfKey(id);
283     },
284
285     /**
286      * Get the Record with the specified id.
287      * @param {String} id The id of the Record to find.
288      * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
289      */
290     getById : function(id){
291         return this.data.key(id);
292     },
293
294     /**
295      * Get the Record at the specified index.
296      * @param {Number} index The index of the Record to find.
297      * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
298      */
299     getAt : function(index){
300         return this.data.itemAt(index);
301     },
302
303     /**
304      * Returns a range of Records between specified indices.
305      * @param {Number} startIndex (optional) The starting index (defaults to 0)
306      * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
307      * @return {Roo.data.Record[]} An array of Records
308      */
309     getRange : function(start, end){
310         return this.data.getRange(start, end);
311     },
312
313     // private
314     storeOptions : function(o){
315         o = Roo.apply({}, o);
316         delete o.callback;
317         delete o.scope;
318         this.lastOptions = o;
319     },
320
321     /**
322      * Loads the Record cache from the configured Proxy using the configured Reader.
323      * <p>
324      * If using remote paging, then the first load call must specify the <em>start</em>
325      * and <em>limit</em> properties in the options.params property to establish the initial
326      * position within the dataset, and the number of Records to cache on each read from the Proxy.
327      * <p>
328      * <strong>It is important to note that for remote data sources, loading is asynchronous,
329      * and this call will return before the new data has been loaded. Perform any post-processing
330      * in a callback function, or in a "load" event handler.</strong>
331      * <p>
332      * @param {Object} options An object containing properties which control loading options:<ul>
333      * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
334      * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
335      * passed the following arguments:<ul>
336      * <li>r : Roo.data.Record[]</li>
337      * <li>options: Options object from the load call</li>
338      * <li>success: Boolean success indicator</li></ul></li>
339      * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
340      * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
341      * </ul>
342      */
343     load : function(options){
344         options = options || {};
345         if(this.fireEvent("beforeload", this, options) !== false){
346             this.storeOptions(options);
347             var p = Roo.apply(options.params || {}, this.baseParams);
348             // if meta was not loaded from remote source.. try requesting it.
349             if (!this.reader.metaFromRemote) {
350                 p._requestMeta = 1;
351             }
352             if(this.sortInfo && this.remoteSort){
353                 var pn = this.paramNames;
354                 p[pn["sort"]] = this.sortInfo.field;
355                 p[pn["dir"]] = this.sortInfo.direction;
356             }
357             if (this.multiSort) {
358                 var pn = this.paramNames;
359                 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
360             }
361             
362             this.proxy.load(p, this.reader, this.loadRecords, this, options);
363         }
364     },
365
366     /**
367      * Reloads the Record cache from the configured Proxy using the configured Reader and
368      * the options from the last load operation performed.
369      * @param {Object} options (optional) An object containing properties which may override the options
370      * used in the last load operation. See {@link #load} for details (defaults to null, in which case
371      * the most recently used options are reused).
372      */
373     reload : function(options){
374         this.load(Roo.applyIf(options||{}, this.lastOptions));
375     },
376
377     // private
378     // Called as a callback by the Reader during a load operation.
379     loadRecords : function(o, options, success){
380         if(!o || success === false){
381             if(success !== false){
382                 this.fireEvent("load", this, [], options, o);
383             }
384             if(options.callback){
385                 options.callback.call(options.scope || this, [], options, false);
386             }
387             return;
388         }
389         // if data returned failure - throw an exception.
390         if (o.success === false) {
391             // show a message if no listener is registered.
392             if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
393                     Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
394             }
395             // loadmask wil be hooked into this..
396             this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
397             return;
398         }
399         var r = o.records, t = o.totalRecords || r.length;
400         
401         this.fireEvent("beforeloadadd", this, r, options, o);
402         
403         if(!options || options.add !== true){
404             if(this.pruneModifiedRecords){
405                 this.modified = [];
406             }
407             for(var i = 0, len = r.length; i < len; i++){
408                 r[i].join(this);
409             }
410             if(this.snapshot){
411                 this.data = this.snapshot;
412                 delete this.snapshot;
413             }
414             this.data.clear();
415             this.data.addAll(r);
416             this.totalLength = t;
417             this.applySort();
418             this.fireEvent("datachanged", this);
419         }else{
420             this.totalLength = Math.max(t, this.data.length+r.length);
421             this.add(r);
422         }
423         this.fireEvent("load", this, r, options, o);
424         if(options.callback){
425             options.callback.call(options.scope || this, r, options, true);
426         }
427     },
428
429
430     /**
431      * Loads data from a passed data block. A Reader which understands the format of the data
432      * must have been configured in the constructor.
433      * @param {Object} data The data block from which to read the Records.  The format of the data expected
434      * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
435      * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
436      */
437     loadData : function(o, append){
438         var r = this.reader.readRecords(o);
439         this.loadRecords(r, {add: append}, true);
440     },
441
442     /**
443      * Gets the number of cached records.
444      * <p>
445      * <em>If using paging, this may not be the total size of the dataset. If the data object
446      * used by the Reader contains the dataset size, then the getTotalCount() function returns
447      * the data set size</em>
448      */
449     getCount : function(){
450         return this.data.length || 0;
451     },
452
453     /**
454      * Gets the total number of records in the dataset as returned by the server.
455      * <p>
456      * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
457      * the dataset size</em>
458      */
459     getTotalCount : function(){
460         return this.totalLength || 0;
461     },
462
463     /**
464      * Returns the sort state of the Store as an object with two properties:
465      * <pre><code>
466  field {String} The name of the field by which the Records are sorted
467  direction {String} The sort order, "ASC" or "DESC"
468      * </code></pre>
469      */
470     getSortState : function(){
471         return this.sortInfo;
472     },
473
474     // private
475     applySort : function(){
476         if(this.sortInfo && !this.remoteSort){
477             var s = this.sortInfo, f = s.field;
478             var st = this.fields.get(f).sortType;
479             var fn = function(r1, r2){
480                 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
481                 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
482             };
483             this.data.sort(s.direction, fn);
484             if(this.snapshot && this.snapshot != this.data){
485                 this.snapshot.sort(s.direction, fn);
486             }
487         }
488     },
489
490     /**
491      * Sets the default sort column and order to be used by the next load operation.
492      * @param {String} fieldName The name of the field to sort by.
493      * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
494      */
495     setDefaultSort : function(field, dir){
496         this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
497     },
498
499     /**
500      * Sort the Records.
501      * If remote sorting is used, the sort is performed on the server, and the cache is
502      * reloaded. If local sorting is used, the cache is sorted internally.
503      * @param {String} fieldName The name of the field to sort by.
504      * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
505      */
506     sort : function(fieldName, dir){
507         var f = this.fields.get(fieldName);
508         if(!dir){
509             this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
510             
511             if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
512                 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
513             }else{
514                 dir = f.sortDir;
515             }
516         }
517         this.sortToggle[f.name] = dir;
518         this.sortInfo = {field: f.name, direction: dir};
519         if(!this.remoteSort){
520             this.applySort();
521             this.fireEvent("datachanged", this);
522         }else{
523             this.load(this.lastOptions);
524         }
525     },
526
527     /**
528      * Calls the specified function for each of the Records in the cache.
529      * @param {Function} fn The function to call. The Record is passed as the first parameter.
530      * Returning <em>false</em> aborts and exits the iteration.
531      * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
532      */
533     each : function(fn, scope){
534         this.data.each(fn, scope);
535     },
536
537     /**
538      * Gets all records modified since the last commit.  Modified records are persisted across load operations
539      * (e.g., during paging).
540      * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
541      */
542     getModifiedRecords : function(){
543         return this.modified;
544     },
545
546     // private
547     createFilterFn : function(property, value, anyMatch){
548         if(!value.exec){ // not a regex
549             value = String(value);
550             if(value.length == 0){
551                 return false;
552             }
553             value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
554         }
555         
556         return function(r){
557             return value.test(r.data[property]);
558         };
559     },
560
561     /**
562      * Sums the value of <i>property</i> for each record between start and end and returns the result.
563      * @param {String} property A field on your records
564      * @param {Number} start The record index to start at (defaults to 0)
565      * @param {Number} end The last record index to include (defaults to length - 1)
566      * @return {Number} The sum
567      */
568     sum : function(property, start, end){
569         var rs = this.data.items, v = 0;
570         start = start || 0;
571         end = (end || end === 0) ? end : rs.length-1;
572
573         for(var i = start; i <= end; i++){
574             v += (rs[i].data[property] || 0);
575         }
576         return v;
577     },
578
579     /**
580      * Filter the records by a specified property.
581      * @param {String} field A field on your records
582      * @param {String/RegExp} value Either a string that the field
583      * should start with or a RegExp to test against the field
584      * @param {Boolean} anyMatch True to match any part not just the beginning
585      */
586     filter : function(property, value, anyMatch){
587         
588         if(typeof(property) == 'string'){
589             var fn = this.createFilterFn(property, value, anyMatch);
590             return fn ? this.filterBy(fn) : this.clearFilter();
591         }
592         
593         var fn = [];
594         var afn = [];
595         
596         var _this = this;
597         
598         Roo.each(property, function(p){
599             if(anyMatch == true){
600                 afn.push(_this.createFilterFn(p, value, true));
601             }
602             
603             fn.push(_this.createFilterFn(p, value, false));
604         });
605         
606         if(!fn.length && !afn.length){
607             return this.clearFilter();
608         }
609         
610         this.snapshot = this.snapshot || this.data;
611         
612         var filterData = [];
613         
614         Roo.each(fn, function(f){
615             filterData.push(_this.queryBy(f, _this));
616         });
617         
618         Roo.each(afn, function(f){
619             filterData.push(_this.queryBy(f, _this));
620         });
621         
622         var data = this.snapshot || this.data;
623         
624         var r = new Roo.util.MixedCollection();
625         r.getKey = data.getKey;
626         
627         var keys =[];
628         
629         Roo.each(filterData, function(d){
630             var k = d.keys, it = d.items;
631             for(var i = 0, len = it.length; i < len; i++){
632                 if(keys.indexOf(k[i]) == -1){
633                     r.add(k[i], it[i]);
634                 }
635             }
636         });
637         
638         r.sort('ASC');
639         
640         this.data = r;
641         this.fireEvent("datachanged", this);
642     },
643
644     /**
645      * Filter by a function. The specified function will be called with each
646      * record in this data source. If the function returns true the record is included,
647      * otherwise it is filtered.
648      * @param {Function} fn The function to be called, it will receive 2 args (record, id)
649      * @param {Object} scope (optional) The scope of the function (defaults to this)
650      */
651     filterBy : function(fn, scope){
652         this.snapshot = this.snapshot || this.data;
653         this.data = this.queryBy(fn, scope||this);
654         this.fireEvent("datachanged", this);
655     },
656
657     /**
658      * Query the records by a specified property.
659      * @param {String} field A field on your records
660      * @param {String/RegExp} value Either a string that the field
661      * should start with or a RegExp to test against the field
662      * @param {Boolean} anyMatch True to match any part not just the beginning
663      * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
664      */
665     query : function(property, value, anyMatch){
666         var fn = this.createFilterFn(property, value, anyMatch);
667         return fn ? this.queryBy(fn) : this.data.clone();
668     },
669
670     /**
671      * Query by a function. The specified function will be called with each
672      * record in this data source. If the function returns true the record is included
673      * in the results.
674      * @param {Function} fn The function to be called, it will receive 2 args (record, id)
675      * @param {Object} scope (optional) The scope of the function (defaults to this)
676       @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
677      **/
678     queryBy : function(fn, scope){
679         var data = this.snapshot || this.data;
680         return data.filterBy(fn, scope||this);
681     },
682
683     /**
684      * Collects unique values for a particular dataIndex from this store.
685      * @param {String} dataIndex The property to collect
686      * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
687      * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
688      * @return {Array} An array of the unique values
689      **/
690     collect : function(dataIndex, allowNull, bypassFilter){
691         var d = (bypassFilter === true && this.snapshot) ?
692                 this.snapshot.items : this.data.items;
693         var v, sv, r = [], l = {};
694         for(var i = 0, len = d.length; i < len; i++){
695             v = d[i].data[dataIndex];
696             sv = String(v);
697             if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
698                 l[sv] = true;
699                 r[r.length] = v;
700             }
701         }
702         return r;
703     },
704
705     /**
706      * Revert to a view of the Record cache with no filtering applied.
707      * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
708      */
709     clearFilter : function(suppressEvent){
710         if(this.snapshot && this.snapshot != this.data){
711             this.data = this.snapshot;
712             delete this.snapshot;
713             if(suppressEvent !== true){
714                 this.fireEvent("datachanged", this);
715             }
716         }
717     },
718
719     // private
720     afterEdit : function(record){
721         if(this.modified.indexOf(record) == -1){
722             this.modified.push(record);
723         }
724         this.fireEvent("update", this, record, Roo.data.Record.EDIT);
725     },
726     
727     // private
728     afterReject : function(record){
729         this.modified.remove(record);
730         this.fireEvent("update", this, record, Roo.data.Record.REJECT);
731     },
732
733     // private
734     afterCommit : function(record){
735         this.modified.remove(record);
736         this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
737     },
738
739     /**
740      * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
741      * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
742      */
743     commitChanges : function(){
744         var m = this.modified.slice(0);
745         this.modified = [];
746         for(var i = 0, len = m.length; i < len; i++){
747             m[i].commit();
748         }
749     },
750
751     /**
752      * Cancel outstanding changes on all changed records.
753      */
754     rejectChanges : function(){
755         var m = this.modified.slice(0);
756         this.modified = [];
757         for(var i = 0, len = m.length; i < len; i++){
758             m[i].reject();
759         }
760     },
761
762     onMetaChange : function(meta, rtype, o){
763         this.recordType = rtype;
764         this.fields = rtype.prototype.fields;
765         delete this.snapshot;
766         this.sortInfo = meta.sortInfo || this.sortInfo;
767         this.modified = [];
768         this.fireEvent('metachange', this, this.reader.meta);
769     },
770     
771     moveIndex : function(data, type)
772     {
773         var index = this.indexOf(data);
774         
775         var newIndex = index + type;
776         
777         this.remove(data);
778         
779         this.insert(newIndex, data);
780         
781     }
782 });