]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This example shows how to enable users to edit the contents of a grid. Note that cell\r | |
3 | * editing is not recommeded on keyboardless touch devices.\r | |
4 | */\r | |
5 | Ext.define('KitchenSink.view.grid.CellEditing', {\r | |
6 | extend: 'Ext.grid.Panel',\r | |
7 | \r | |
8 | requires: [\r | |
9 | 'Ext.selection.CellModel',\r | |
10 | 'Ext.grid.*',\r | |
11 | 'Ext.data.*',\r | |
12 | 'Ext.util.*',\r | |
13 | 'Ext.form.*',\r | |
14 | 'KitchenSink.model.grid.Plant'\r | |
15 | ],\r | |
16 | xtype: 'cell-editing',\r | |
17 | \r | |
18 | //<example>\r | |
19 | exampleTitle: 'Cell Editing Grid Example',\r | |
20 | otherContent: [{\r | |
21 | type: 'Model',\r | |
22 | path: 'classic/samples/model/grid/Plant.js'\r | |
23 | }],\r | |
24 | profiles: {\r | |
25 | classic: {\r | |
26 | width: 600,\r | |
27 | height: 300,\r | |
28 | indoorWidth: 55,\r | |
29 | priceWidth: 70,\r | |
30 | avaliableWidth: 95\r | |
31 | },\r | |
32 | neptune: {\r | |
33 | width: 680,\r | |
34 | height: 350,\r | |
35 | indoorWidth: 90,\r | |
36 | priceWidth: 70,\r | |
37 | avaliableWidth: 95\r | |
38 | },\r | |
39 | 'neptune-touch': {\r | |
40 | priceWidth: 115,\r | |
41 | availableWidth: 120\r | |
42 | }\r | |
43 | },\r | |
44 | //</example>\r | |
45 | \r | |
46 | title: 'Edit Plants',\r | |
47 | frame: true,\r | |
48 | \r | |
49 | initComponent: function() {\r | |
50 | this.cellEditing = new Ext.grid.plugin.CellEditing({\r | |
51 | clicksToEdit: 1\r | |
52 | });\r | |
53 | \r | |
54 | Ext.apply(this, {\r | |
55 | width: this.profileInfo.width,\r | |
56 | height: this.profileInfo.height,\r | |
57 | plugins: [this.cellEditing],\r | |
58 | store: new Ext.data.Store({\r | |
59 | // destroy the store if the grid is destroyed\r | |
60 | autoDestroy: true,\r | |
61 | model: KitchenSink.model.grid.Plant,\r | |
62 | proxy: {\r | |
63 | type: 'ajax',\r | |
64 | // load remote data using HTTP\r | |
65 | url: 'data/grid/plants.xml',\r | |
66 | // specify a XmlReader (coincides with the XML format of the returned data)\r | |
67 | reader: {\r | |
68 | type: 'xml',\r | |
69 | // records will have a 'plant' tag\r | |
70 | record: 'plant'\r | |
71 | }\r | |
72 | },\r | |
73 | sorters: [{\r | |
74 | property: 'common',\r | |
75 | direction:'ASC'\r | |
76 | }]\r | |
77 | }),\r | |
78 | columns: [{\r | |
79 | header: 'Common Name',\r | |
80 | dataIndex: 'common',\r | |
81 | flex: 1,\r | |
82 | editor: {\r | |
83 | allowBlank: false\r | |
84 | }\r | |
85 | }, {\r | |
86 | header: 'Light',\r | |
87 | dataIndex: 'light',\r | |
88 | width: 130,\r | |
89 | editor: new Ext.form.field.ComboBox({\r | |
90 | typeAhead: true,\r | |
91 | triggerAction: 'all',\r | |
92 | store: [\r | |
93 | ['Shade','Shade'],\r | |
94 | ['Mostly Shady','Mostly Shady'],\r | |
95 | ['Sun or Shade','Sun or Shade'],\r | |
96 | ['Mostly Sunny','Mostly Sunny'],\r | |
97 | ['Sunny','Sunny']\r | |
98 | ]\r | |
99 | })\r | |
100 | }, {\r | |
101 | header: 'Price',\r | |
102 | dataIndex: 'price',\r | |
103 | width: this.profileInfo.priceWidth,\r | |
104 | align: 'right',\r | |
105 | formatter: 'usMoney',\r | |
106 | editor: {\r | |
107 | xtype: 'numberfield',\r | |
108 | allowBlank: false,\r | |
109 | minValue: 0,\r | |
110 | maxValue: 100000\r | |
111 | }\r | |
112 | }, {\r | |
113 | header: 'Available',\r | |
114 | dataIndex: 'availDate',\r | |
115 | xtype: 'datecolumn',\r | |
116 | width: this.profileInfo.availableWidth,\r | |
117 | format: 'M d, Y',\r | |
118 | editor: {\r | |
119 | xtype: 'datefield',\r | |
120 | format: 'm/d/y',\r | |
121 | minValue: '01/01/06',\r | |
122 | disabledDays: [0, 6],\r | |
123 | disabledDaysText: 'Plants are not available on the weekends'\r | |
124 | }\r | |
125 | }, {\r | |
126 | xtype: 'checkcolumn',\r | |
127 | header: 'Indoor?',\r | |
128 | dataIndex: 'indoor',\r | |
129 | width: this.profileInfo.indoorWidth,\r | |
130 | stopSelection: false\r | |
131 | }, {\r | |
132 | xtype: 'actioncolumn',\r | |
133 | width: 30,\r | |
134 | sortable: false,\r | |
135 | menuDisabled: true,\r | |
136 | items: [{\r | |
137 | iconCls: 'cell-editing-delete-row',\r | |
138 | tooltip: 'Delete Plant',\r | |
139 | scope: this,\r | |
140 | handler: this.onRemoveClick\r | |
141 | }]\r | |
142 | }],\r | |
143 | selModel: {\r | |
144 | type: 'cellmodel'\r | |
145 | },\r | |
146 | tbar: [{\r | |
147 | text: 'Add Plant',\r | |
148 | scope: this,\r | |
149 | handler: this.onAddClick\r | |
150 | }]\r | |
151 | });\r | |
152 | \r | |
153 | this.callParent();\r | |
154 | \r | |
155 | if (Ext.supports.Touch) {\r | |
156 | this.addDocked({\r | |
157 | xtype: 'header',\r | |
158 | title: '<b>Note that cell editing is not recommeded on keyboardless touch devices.</b>'\r | |
159 | });\r | |
160 | }\r | |
161 | \r | |
162 | this.on('afterlayout', this.loadStore, this, {\r | |
163 | delay: 1,\r | |
164 | single: true\r | |
165 | });\r | |
166 | },\r | |
167 | \r | |
168 | loadStore: function() {\r | |
169 | this.getStore().load();\r | |
170 | },\r | |
171 | \r | |
172 | onAddClick: function(){\r | |
173 | // Create a model instance\r | |
174 | var rec = new KitchenSink.model.grid.Plant({\r | |
175 | common: '',\r | |
176 | light: 'Mostly Shady',\r | |
177 | price: 0,\r | |
178 | availDate: Ext.Date.clearTime(new Date()),\r | |
179 | indoor: false\r | |
180 | });\r | |
181 | \r | |
182 | this.getStore().insert(0, rec);\r | |
183 | this.cellEditing.startEditByPosition({\r | |
184 | row: 0,\r | |
185 | column: 0\r | |
186 | });\r | |
187 | },\r | |
188 | \r | |
189 | onRemoveClick: function(grid, rowIndex){\r | |
190 | this.getStore().removeAt(rowIndex);\r | |
191 | }\r | |
192 | });\r |