3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.grid.EditorGridPanel"></div>/**
10 * @class Ext.grid.EditorGridPanel
11 * @extends Ext.grid.GridPanel
12 * <p>This class extends the {@link Ext.grid.GridPanel GridPanel Class} to provide cell editing
13 * on selected {@link Ext.grid.Column columns}. The editable columns are specified by providing
14 * an {@link Ext.grid.ColumnModel#editor editor} in the {@link Ext.grid.Column column configuration}.</p>
15 * <p>Editability of columns may be controlled programatically by inserting an implementation
16 * of {@link Ext.grid.ColumnModel#isCellEditable isCellEditable} into the
17 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
18 * <p>Editing is performed on the value of the <i>field</i> specified by the column's
19 * <tt>{@link Ext.grid.ColumnModel#dataIndex dataIndex}</tt> in the backing {@link Ext.data.Store Store}
20 * (so if you are using a {@link Ext.grid.ColumnModel#setRenderer renderer} in order to display
21 * transformed data, this must be accounted for).</p>
22 * <p>If a value-to-description mapping is used to render a column, then a {@link Ext.form.Field#ComboBox ComboBox}
23 * which uses the same {@link Ext.form.Field#valueField value}-to-{@link Ext.form.Field#displayFieldField description}
24 * mapping would be an appropriate editor.</p>
25 * If there is a more complex mismatch between the visible data in the grid, and the editable data in
26 * the {@link Edt.data.Store Store}, then code to transform the data both before and after editing can be
27 * injected using the {@link #beforeedit} and {@link #afteredit} events.
29 * @param {Object} config The config object
32 Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
33 <div id="cfg-Ext.grid.EditorGridPanel-clicksToEdit"></div>/**
34 * @cfg {Number} clicksToEdit
35 * <p>The number of clicks on a cell required to display the cell's editor (defaults to 2).</p>
36 * <p>Setting this option to 'auto' means that mousedown <i>on the selected cell</i> starts
37 * editing that cell.</p>
41 <div id="cfg-Ext.grid.EditorGridPanel-forceValidation"></div>/**
42 * @cfg {Boolean} forceValidation
43 * True to force validation even if the value is unmodified (defaults to false)
45 forceValidation: false,
52 <div id="cfg-Ext.grid.EditorGridPanel-autoEncode"></div>/**
53 * @cfg {Boolean} autoEncode
54 * True to automatically HTML encode and decode values pre and post edit (defaults to false)
58 <div id="cfg-Ext.grid.EditorGridPanel-trackMouseOver"></div>/**
59 * @cfg {Boolean} trackMouseOver @hide
62 trackMouseOver: false, // causes very odd FF errors
65 initComponent : function(){
66 Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
69 <div id="cfg-Ext.grid.EditorGridPanel-selModel"></div>/**
70 * @cfg {Object} selModel Any subclass of AbstractSelectionModel that will provide the selection model for
71 * the grid (defaults to {@link Ext.grid.CellSelectionModel} if not specified).
73 this.selModel = new Ext.grid.CellSelectionModel();
76 this.activeEditor = null;
79 <div id="event-Ext.grid.EditorGridPanel-beforeedit"></div>/**
81 * Fires before cell editing is triggered. The edit event object has the following properties <br />
82 * <ul style="padding:5px;padding-left:16px;">
83 * <li>grid - This grid</li>
84 * <li>record - The record being edited</li>
85 * <li>field - The field name being edited</li>
86 * <li>value - The value for the field being edited.</li>
87 * <li>row - The grid row index</li>
88 * <li>column - The grid column index</li>
89 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
91 * @param {Object} e An edit event (see above for description)
94 <div id="event-Ext.grid.EditorGridPanel-afteredit"></div>/**
96 * Fires after a cell is edited. The edit event object has the following properties <br />
97 * <ul style="padding:5px;padding-left:16px;">
98 * <li>grid - This grid</li>
99 * <li>record - The record being edited</li>
100 * <li>field - The field name being edited</li>
101 * <li>value - The value being set</li>
102 * <li>originalValue - The original value for the field, before the edit.</li>
103 * <li>row - The grid row index</li>
104 * <li>column - The grid column index</li>
108 grid.on('afteredit', afterEdit, this );
110 function afterEdit(e) {
111 // execute an XHR to send/commit data to the server, in callback do (if successful):
115 * @param {Object} e An edit event (see above for description)
118 <div id="event-Ext.grid.EditorGridPanel-validateedit"></div>/**
119 * @event validateedit
120 * Fires after a cell is edited, but before the value is set in the record. Return false
121 * to cancel the change. The edit event object has the following properties <br />
122 * <ul style="padding:5px;padding-left:16px;">
123 * <li>grid - This grid</li>
124 * <li>record - The record being edited</li>
125 * <li>field - The field name being edited</li>
126 * <li>value - The value being set</li>
127 * <li>originalValue - The original value for the field, before the edit.</li>
128 * <li>row - The grid row index</li>
129 * <li>column - The grid column index</li>
130 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
132 * Usage example showing how to remove the red triangle (dirty record indicator) from some
133 * records (not all). By observing the grid's validateedit event, it can be cancelled if
134 * the edit occurs on a targeted row (for example) and then setting the field's new value
135 * in the Record directly:
137 grid.on('validateedit', function(e) {
140 if (e.row == myTargetRow) {
142 e.record.data[e.field] = e.value;
146 * @param {Object} e An edit event (see above for description)
153 initEvents : function(){
154 Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
156 this.getGridEl().on('mousewheel', this.stopEditing.createDelegate(this, [true]), this);
157 this.on('columnresize', this.stopEditing, this, [true]);
159 if(this.clicksToEdit == 1){
160 this.on("cellclick", this.onCellDblClick, this);
162 var view = this.getView();
163 if(this.clicksToEdit == 'auto' && view.mainBody){
164 view.mainBody.on('mousedown', this.onAutoEditClick, this);
166 this.on('celldblclick', this.onCellDblClick, this);
170 onResize : function(){
171 Ext.grid.EditorGridPanel.superclass.onResize.apply(this, arguments);
172 var ae = this.activeEditor;
173 if(this.editing && ae){
179 onCellDblClick : function(g, row, col){
180 this.startEditing(row, col);
184 onAutoEditClick : function(e, t){
188 var row = this.view.findRowIndex(t),
189 col = this.view.findCellIndex(t);
190 if(row !== false && col !== false){
192 if(this.selModel.getSelectedCell){ // cell sm
193 var sc = this.selModel.getSelectedCell();
194 if(sc && sc[0] === row && sc[1] === col){
195 this.startEditing(row, col);
198 if(this.selModel.isSelected(row)){
199 this.startEditing(row, col);
206 onEditComplete : function(ed, value, startValue){
207 this.editing = false;
208 this.activeEditor = null;
211 field = this.colModel.getDataIndex(ed.col);
212 value = this.postEditValue(value, startValue, r, field);
213 if(this.forceValidation === true || String(value) !== String(startValue)){
218 originalValue: startValue,
224 if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){
225 r.set(field, e.value);
227 this.fireEvent("afteredit", e);
230 this.view.focusCell(ed.row, ed.col);
233 <div id="method-Ext.grid.EditorGridPanel-startEditing"></div>/**
234 * Starts editing the specified for the specified row/column
235 * @param {Number} rowIndex
236 * @param {Number} colIndex
238 startEditing : function(row, col){
240 if(this.colModel.isCellEditable(col, row)){
241 this.view.ensureVisible(row, col, true);
242 var r = this.store.getAt(row),
243 field = this.colModel.getDataIndex(col),
248 value: r.data[field],
253 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
255 var ed = this.colModel.getCellEditor(col, row);
260 ed.parentEl = this.view.getEditorParent(ed);
265 c.field.focus(false, true);
270 specialkey: function(field, e){
271 this.getSelectionModel().onEditorKey(field, e);
273 complete: this.onEditComplete,
274 canceledit: this.stopEditing.createDelegate(this, [true])
286 this.activeEditor = ed;
287 // Set the selectSameEditor flag if we are reusing the same editor again and
288 // need to prevent the editor from firing onBlur on itself.
289 ed.selectSameEditor = (this.activeEditor == this.lastActiveEditor);
290 var v = this.preEditValue(r, field);
291 ed.startEdit(this.view.getCell(row, col).firstChild, Ext.isDefined(v) ? v : '');
293 // Clear the selectSameEditor flag
295 delete ed.selectSameEditor;
302 preEditValue : function(r, field){
303 var value = r.data[field];
304 return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlDecode(value) : value;
308 postEditValue : function(value, originalValue, r, field){
309 return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlEncode(value) : value;
312 <div id="method-Ext.grid.EditorGridPanel-stopEditing"></div>/**
313 * Stops any active editing
314 * @param {Boolean} cancel (optional) True to cancel any changes
316 stopEditing : function(cancel){
318 // Store the lastActiveEditor to check if it is changing
319 var ae = this.lastActiveEditor = this.activeEditor;
321 ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
322 this.view.focusCell(ae.row, ae.col);
324 this.activeEditor = null;
326 this.editing = false;
329 Ext.reg('editorgrid', Ext.grid.EditorGridPanel);</pre>
\r