commit extjs-2.2.1
[extjs.git] / examples / grid / binding.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 Ext.onReady(function(){\r
10         \r
11     // create the Data Store\r
12     var store = new Ext.data.Store({\r
13         // load using HTTP\r
14         url: 'sheldon.xml',\r
15 \r
16         // the return will be XML, so lets set up a reader\r
17         reader: new Ext.data.XmlReader({\r
18                // records will have an "Item" tag\r
19                record: 'Item',\r
20                id: 'ASIN',\r
21                totalRecords: '@total'\r
22            }, [\r
23                // set up the fields mapping into the xml doc\r
24                // The first needs mapping, the others are very basic\r
25                {name: 'Author', mapping: 'ItemAttributes > Author'},\r
26                'Title',\r
27                            'Manufacturer',\r
28                            'ProductGroup',\r
29                            // Detail URL is not part of the column model of the grid\r
30                            'DetailPageURL'\r
31            ])\r
32     });\r
33 \r
34     // create the grid\r
35     var grid = new Ext.grid.GridPanel({\r
36         store: store,\r
37         columns: [\r
38             {header: "Author", width: 120, dataIndex: 'Author', sortable: true},\r
39             {header: "Title", width: 180, dataIndex: 'Title', sortable: true},\r
40             {header: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},\r
41             {header: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}\r
42         ],\r
43                 sm: new Ext.grid.RowSelectionModel({singleSelect: true}),\r
44                 viewConfig: {\r
45                         forceFit: true\r
46                 },\r
47         height:210,\r
48                 split: true,\r
49                 region: 'north'\r
50     });\r
51         \r
52         // define a template to use for the detail view\r
53         var bookTplMarkup = [\r
54                 'Title: <a href="{DetailPageURL}" target="_blank">{Title}</a><br/>',\r
55                 'Author: {Author}<br/>',\r
56                 'Manufacturer: {Manufacturer}<br/>',\r
57                 'Product Group: {ProductGroup}<br/>'\r
58         ];\r
59         var bookTpl = new Ext.Template(bookTplMarkup);\r
60 \r
61         var ct = new Ext.Panel({\r
62                 renderTo: 'binding-example',\r
63                 frame: true,\r
64                 title: 'Book List',\r
65                 width: 540,\r
66                 height: 400,\r
67                 layout: 'border',\r
68                 items: [\r
69                         grid,\r
70                         {\r
71                                 id: 'detailPanel',\r
72                                 region: 'center',\r
73                                 bodyStyle: {\r
74                                         background: '#ffffff',\r
75                                         padding: '7px'\r
76                                 },\r
77                                 html: 'Please select a book to see additional details.'\r
78                         }\r
79                 ]\r
80         })\r
81         grid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) {\r
82                 var detailPanel = Ext.getCmp('detailPanel');\r
83                 bookTpl.overwrite(detailPanel.body, r.data);\r
84         });\r
85     store.load();\r
86 });