Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / src / data / ArrayStore.js
1 /*!
2  * Ext JS Library 3.2.1
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.data.ArrayStore
9  * @extends Ext.data.Store
10  * <p>Formerly known as "SimpleStore".</p>
11  * <p>Small helper class to make creating {@link Ext.data.Store}s from Array data easier.
12  * An ArrayStore will be automatically configured with a {@link Ext.data.ArrayReader}.</p>
13  * <p>A store configuration would be something like:<pre><code>
14 var store = new Ext.data.ArrayStore({
15     // store configs
16     autoDestroy: true,
17     storeId: 'myStore',
18     // reader configs
19     idIndex: 0,  
20     fields: [
21        'company',
22        {name: 'price', type: 'float'},
23        {name: 'change', type: 'float'},
24        {name: 'pctChange', type: 'float'},
25        {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
26     ]
27 });
28  * </code></pre></p>
29  * <p>This store is configured to consume a returned object of the form:<pre><code>
30 var myData = [
31     ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
32     ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
33     ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
34     ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
35     ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
36 ];
37  * </code></pre>
38  * An object literal of this form could also be used as the {@link #data} config option.</p>
39  * <p><b>*Note:</b> Although not listed here, this class accepts all of the configuration options of 
40  * <b>{@link Ext.data.ArrayReader ArrayReader}</b>.</p>
41  * @constructor
42  * @param {Object} config
43  * @xtype arraystore
44  */
45 Ext.data.ArrayStore = Ext.extend(Ext.data.Store, {
46     /**
47      * @cfg {Ext.data.DataReader} reader @hide
48      */
49     constructor: function(config){
50         Ext.data.ArrayStore.superclass.constructor.call(this, Ext.apply(config, {
51             reader: new Ext.data.ArrayReader(config)
52         }));
53     },
54
55     loadData : function(data, append){
56         if(this.expandData === true){
57             var r = [];
58             for(var i = 0, len = data.length; i < len; i++){
59                 r[r.length] = [data[i]];
60             }
61             data = r;
62         }
63         Ext.data.ArrayStore.superclass.loadData.call(this, data, append);
64     }
65 });
66 Ext.reg('arraystore', Ext.data.ArrayStore);
67
68 // backwards compat
69 Ext.data.SimpleStore = Ext.data.ArrayStore;
70 Ext.reg('simplestore', Ext.data.SimpleStore);