3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.onReady(function(){
\r
9 Ext.QuickTips.init();
\r
11 function formatDate(value){
\r
12 return value ? value.dateFormat('M d, Y') : '';
\r
17 // custom column plugin example
\r
18 var checkColumn = new Ext.grid.CheckColumn({
\r
20 dataIndex: 'indoor',
\r
24 // the column model has information about grid columns
\r
25 // dataIndex maps the column to the specific data field in
\r
26 // the data store (created below)
\r
27 var cm = new Ext.grid.ColumnModel([{
\r
29 header: 'Common Name',
\r
30 dataIndex: 'common',
\r
32 // use shorthand alias defined above
\r
33 editor: new fm.TextField({
\r
40 editor: new fm.ComboBox({
\r
42 triggerAction: 'all',
\r
45 listClass: 'x-combo-list-small'
\r
52 renderer: 'usMoney',
\r
53 editor: new fm.NumberField({
\r
55 allowNegative: false,
\r
59 header: 'Available',
\r
60 dataIndex: 'availDate',
\r
62 renderer: formatDate,
\r
63 editor: new fm.DateField({
\r
65 minValue: '01/01/06',
\r
66 disabledDays: [0, 6],
\r
67 disabledDaysText: 'Plants are not available on the weekends'
\r
73 // by default columns are sortable
\r
74 cm.defaultSortable = true;
\r
76 // create the Data Store
\r
77 var store = new Ext.data.Store({
\r
78 // load remote data using HTTP
\r
81 // specify a XmlReader (coincides with the XML format of the returned data)
\r
82 reader: new Ext.data.XmlReader(
\r
84 // records will have a 'plant' tag
\r
87 // use an Array of field definition objects to implicitly create a Record constructor
\r
89 // the 'name' below matches the tag name to read, except 'availDate'
\r
90 // which is mapped to the tag 'availability'
\r
91 {name: 'common', type: 'string'},
\r
92 {name: 'botanical', type: 'string'},
\r
94 {name: 'price', type: 'float'},
\r
95 // dates can be automatically converted by specifying dateFormat
\r
96 {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
\r
97 {name: 'indoor', type: 'bool'}
\r
101 sortInfo: {field:'common', direction:'ASC'}
\r
104 // create the editor grid
\r
105 var grid = new Ext.grid.EditorGridPanel({
\r
108 renderTo: 'editor-grid',
\r
111 autoExpandColumn: 'common',
\r
112 title: 'Edit Plants?',
\r
114 plugins: checkColumn,
\r
118 handler : function(){
\r
119 // access the Record constructor through the grid's store
\r
120 var Plant = grid.getStore().recordType;
\r
121 var p = new Plant({
\r
122 common: 'New Plant 1',
\r
123 light: 'Mostly Shade',
\r
125 availDate: (new Date()).clearTime(),
\r
128 grid.stopEditing();
\r
129 store.insert(0, p);
\r
130 grid.startEditing(0, 0);
\r
135 // trigger the data store load
\r