2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.onReady(function(){
\r
10 Ext.QuickTips.init();
\r
12 function formatDate(value){
\r
13 return value ? value.dateFormat('M d, Y') : '';
\r
18 // custom column plugin example
\r
19 var checkColumn = new Ext.grid.CheckColumn({
\r
21 dataIndex: 'indoor',
\r
25 // the column model has information about grid columns
\r
26 // dataIndex maps the column to the specific data field in
\r
27 // the data store (created below)
\r
28 var cm = new Ext.grid.ColumnModel([{
\r
30 header: "Common Name",
\r
31 dataIndex: 'common',
\r
33 editor: new fm.TextField({
\r
40 editor: new Ext.form.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 // this could be inline, but we want to define the Plant record
\r
77 // type so we can add records dynamically
\r
78 var Plant = Ext.data.Record.create([
\r
79 // the "name" below matches the tag name to read, except "availDate"
\r
80 // which is mapped to the tag "availability"
\r
81 {name: 'common', type: 'string'},
\r
82 {name: 'botanical', type: 'string'},
\r
84 {name: 'price', type: 'float'}, // automatic date conversions
\r
85 {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
\r
86 {name: 'indoor', type: 'bool'}
\r
89 // create the Data Store
\r
90 var store = new Ext.data.Store({
\r
94 // the return will be XML, so lets set up a reader
\r
95 reader: new Ext.data.XmlReader({
\r
96 // records will have a "plant" tag
\r
100 sortInfo:{field:'common', direction:'ASC'}
\r
103 // create the editor grid
\r
104 var grid = new Ext.grid.EditorGridPanel({
\r
107 renderTo: 'editor-grid',
\r
110 autoExpandColumn:'common',
\r
111 title:'Edit Plants?',
\r
113 plugins:checkColumn,
\r
118 handler : function(){
\r
119 var p = new Plant({
\r
120 common: 'New Plant 1',
\r
121 light: 'Mostly Shade',
\r
123 availDate: (new Date()).clearTime(),
\r
126 grid.stopEditing();
\r
127 store.insert(0, p);
\r
128 grid.startEditing(0, 0);
\r
133 // trigger the data store load
\r
137 Ext.grid.CheckColumn = function(config){
\r
138 Ext.apply(this, config);
\r
140 this.id = Ext.id();
\r
142 this.renderer = this.renderer.createDelegate(this);
\r
145 Ext.grid.CheckColumn.prototype ={
\r
146 init : function(grid){
\r
148 this.grid.on('render', function(){
\r
149 var view = this.grid.getView();
\r
150 view.mainBody.on('mousedown', this.onMouseDown, this);
\r
154 onMouseDown : function(e, t){
\r
155 if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
\r
157 var index = this.grid.getView().findRowIndex(t);
\r
158 var record = this.grid.store.getAt(index);
\r
159 record.set(this.dataIndex, !record.data[this.dataIndex]);
\r
163 renderer : function(v, p, record){
\r
164 p.css += ' x-grid3-check-col-td';
\r
165 return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
\r