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