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