Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / source / ArrayStore.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-data-ArrayStore-method-constructor'><span id='Ext-data-ArrayStore'>/**
19 </span></span> * @author Ed Spencer
20  * @class Ext.data.ArrayStore
21  * @extends Ext.data.Store
22  * @ignore
23  *
24  * &lt;p&gt;Small helper class to make creating {@link Ext.data.Store}s from Array data easier.
25  * An ArrayStore will be automatically configured with a {@link Ext.data.reader.Array}.&lt;/p&gt;
26  *
27  * &lt;p&gt;A store configuration would be something like:&lt;/p&gt;
28 &lt;pre&gt;&lt;code&gt;
29 var store = new Ext.data.ArrayStore({
30     // store configs
31     autoDestroy: true,
32     storeId: 'myStore',
33     // reader configs
34     idIndex: 0,
35     fields: [
36        'company',
37        {name: 'price', type: 'float'},
38        {name: 'change', type: 'float'},
39        {name: 'pctChange', type: 'float'},
40        {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
41     ]
42 });
43 &lt;/code&gt;&lt;/pre&gt;
44  * &lt;p&gt;This store is configured to consume a returned object of the form:
45 &lt;pre&gt;&lt;code&gt;
46 var myData = [
47     ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
48     ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
49     ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
50     ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
51     ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
52 ];
53 &lt;/code&gt;&lt;/pre&gt;
54 *
55  * &lt;p&gt;An object literal of this form could also be used as the {@link #data} config option.&lt;/p&gt;
56  *
57  * &lt;p&gt;&lt;b&gt;*Note:&lt;/b&gt; Although not listed here, this class accepts all of the configuration options of
58  * &lt;b&gt;{@link Ext.data.reader.Array ArrayReader}&lt;/b&gt;.&lt;/p&gt;
59  *
60  * @constructor
61  * @param {Object} config
62  * @xtype arraystore
63  */
64 Ext.define('Ext.data.ArrayStore', {
65     extend: 'Ext.data.Store',
66     alias: 'store.array',
67     uses: ['Ext.data.reader.Array'],
68
69 <span id='Ext-data-ArrayStore-cfg-reader'>    /**
70 </span>     * @cfg {Ext.data.DataReader} reader @hide
71      */
72     constructor: function(config) {
73         config = config || {};
74
75         Ext.applyIf(config, {
76             proxy: {
77                 type: 'memory',
78                 reader: 'array'
79             }
80         });
81
82         this.callParent([config]);
83     },
84
85     loadData: function(data, append) {
86         if (this.expandData === true) {
87             var r = [],
88                 i = 0,
89                 ln = data.length;
90
91             for (; i &lt; ln; i++) {
92                 r[r.length] = [data[i]];
93             }
94
95             data = r;
96         }
97
98         this.callParent([data, append]);
99     }
100 }, function() {
101     // backwards compat
102     Ext.data.SimpleStore = Ext.data.ArrayStore;
103     // Ext.reg('simplestore', Ext.data.SimpleStore);
104 });
105 </pre>
106 </body>
107 </html>