Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / grid / xml-grid.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 Ext.require([
16     'Ext.data.*',
17     'Ext.grid.*'
18 ]);
19
20 Ext.onReady(function(){
21     Ext.define('Book',{
22         extend: 'Ext.data.Model',
23         fields: [
24             // set up the fields mapping into the xml doc
25             // The first needs mapping, the others are very basic
26             {name: 'Author', mapping: 'ItemAttributes > Author'},
27             'Title', 'Manufacturer', 'ProductGroup'
28         ]
29     });
30
31     // create the Data Store
32     var store = Ext.create('Ext.data.Store', {
33         model: 'Book',
34         autoLoad: true,
35         proxy: {
36             // load using HTTP
37             type: 'ajax',
38             url: 'sheldon.xml',
39             // the return will be XML, so lets set up a reader
40             reader: {
41                 type: 'xml',
42                 // records will have an "Item" tag
43                 record: 'Item',
44                 idProperty: 'ASIN',
45                 totalRecords: '@total'
46             }
47         }
48     });
49
50     // create the grid
51     var grid = Ext.create('Ext.grid.Panel', {
52         store: store,
53         columns: [
54             {text: "Author", flex: 1, dataIndex: 'Author', sortable: true},
55             {text: "Title", width: 180, dataIndex: 'Title', sortable: true},
56             {text: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
57             {text: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
58         ],
59         renderTo:'example-grid',
60         width: 540,
61         height: 200
62     });
63 });
64