3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.onReady(function(){
\r
10 * Handler specified for the 'Available' column renderer
\r
11 * @param {Object} value
\r
13 function formatDate(value){
\r
14 return value ? value.dateFormat('M d, Y') : '';
\r
20 // the check column is created using a custom plugin
\r
21 var checkColumn = new Ext.grid.CheckColumn({
\r
23 dataIndex: 'indoor',
\r
27 // the column model has information about grid columns
\r
28 // dataIndex maps the column to the specific data field in
\r
29 // the data store (created below)
\r
30 var cm = new Ext.grid.ColumnModel({
\r
31 // specify any defaults for each column
\r
33 sortable: true // columns are not sortable by default
\r
38 header: 'Common Name',
\r
39 dataIndex: 'common',
\r
41 // use shorthand alias defined above
\r
42 editor: new fm.TextField({
\r
49 editor: new fm.ComboBox({
\r
51 triggerAction: 'all',
\r
52 // transform the data already specified in html
\r
55 listClass: 'x-combo-list-small'
\r
62 renderer: 'usMoney',
\r
63 editor: new fm.NumberField({
\r
65 allowNegative: false,
\r
69 header: 'Available',
\r
70 dataIndex: 'availDate',
\r
72 renderer: formatDate,
\r
73 editor: new fm.DateField({
\r
75 minValue: '01/01/06',
\r
76 disabledDays: [0, 6],
\r
77 disabledDaysText: 'Plants are not available on the weekends'
\r
80 checkColumn // the plugin instance
\r
84 // create the Data Store
\r
85 var store = new Ext.data.Store({
\r
86 // destroy the store if the grid is destroyed
\r
89 // load remote data using HTTP
\r
92 // specify a XmlReader (coincides with the XML format of the returned data)
\r
93 reader: new Ext.data.XmlReader({
\r
94 // records will have a 'plant' tag
\r
96 // use an Array of field definition objects to implicitly create a Record constructor
\r
98 // the 'name' below matches the tag name to read, except 'availDate'
\r
99 // which is mapped to the tag 'availability'
\r
100 {name: 'common', type: 'string'},
\r
101 {name: 'botanical', type: 'string'},
\r
103 {name: 'price', type: 'float'},
\r
104 // dates can be automatically converted by specifying dateFormat
\r
105 {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
\r
106 {name: 'indoor', type: 'bool'}
\r
110 sortInfo: {field:'common', direction:'ASC'}
\r
113 // create the editor grid
\r
114 var grid = new Ext.grid.EditorGridPanel({
\r
117 renderTo: 'editor-grid',
\r
120 autoExpandColumn: 'common', // column with this id will be expanded
\r
121 title: 'Edit Plants?',
\r
123 // specify the check column plugin on the grid so the plugin is initialized
\r
124 plugins: checkColumn,
\r
128 handler : function(){
\r
129 // access the Record constructor through the grid's store
\r
130 var Plant = grid.getStore().recordType;
\r
131 var p = new Plant({
\r
132 common: 'New Plant 1',
\r
133 light: 'Mostly Shade',
\r
135 availDate: (new Date()).clearTime(),
\r
138 grid.stopEditing();
\r
139 store.insert(0, p);
\r
140 grid.startEditing(0, 0);
\r
145 // manually trigger the data store load
\r
147 // store loading is asynchronous, use a load listener or callback to handle results
\r
148 callback: function(){
\r
150 title: 'Store Load Callback',
\r
151 msg: 'store was loaded, data available for processing',
\r
153 icon: Ext.Msg.INFO,
\r
154 buttons: Ext.Msg.OK
\r