source: trunk/web/addons/job_monarch/lib/extjs/examples/grid/binding.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

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