Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / data / ArrayStore.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @author Ed Spencer
17  *
18  * Small helper class to make creating {@link Ext.data.Store}s from Array data easier. An ArrayStore will be
19  * automatically configured with a {@link Ext.data.reader.Array}.
20  *
21  * A store configuration would be something like:
22  *
23  *     var store = Ext.create('Ext.data.ArrayStore', {
24  *         // store configs
25  *         autoDestroy: true,
26  *         storeId: 'myStore',
27  *         // reader configs
28  *         idIndex: 0,
29  *         fields: [
30  *            'company',
31  *            {name: 'price', type: 'float'},
32  *            {name: 'change', type: 'float'},
33  *            {name: 'pctChange', type: 'float'},
34  *            {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
35  *         ]
36  *     });
37  *
38  * This store is configured to consume a returned object of the form:
39  *
40  *     var myData = [
41  *         ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
42  *         ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
43  *         ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
44  *         ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
45  *         ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
46  *     ];
47  *
48  * An object literal of this form could also be used as the {@link #data} config option.
49  *
50  * **Note:** This class accepts all of the configuration options of {@link Ext.data.reader.Array ArrayReader}.
51  */
52 Ext.define('Ext.data.ArrayStore', {
53     extend: 'Ext.data.Store',
54     alias: 'store.array',
55     uses: ['Ext.data.reader.Array'],
56
57     constructor: function(config) {
58         config = config || {};
59
60         Ext.applyIf(config, {
61             proxy: {
62                 type: 'memory',
63                 reader: 'array'
64             }
65         });
66
67         this.callParent([config]);
68     },
69
70     loadData: function(data, append) {
71         if (this.expandData === true) {
72             var r = [],
73                 i = 0,
74                 ln = data.length;
75
76             for (; i < ln; i++) {
77                 r[r.length] = [data[i]];
78             }
79
80             data = r;
81         }
82
83         this.callParent([data, append]);
84     }
85 }, function() {
86     // backwards compat
87     Ext.data.SimpleStore = Ext.data.ArrayStore;
88     // Ext.reg('simplestore', Ext.data.SimpleStore);
89 });
90