3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.grid.EditorGridPanel"></div>/**
16 * @class Ext.grid.EditorGridPanel
17 * @extends Ext.grid.GridPanel
18 * <p>This class extends the {@link Ext.grid.GridPanel GridPanel Class} to provide cell editing
19 * on selected {@link Ext.grid.Column columns}. The editable columns are specified by providing
20 * an {@link Ext.grid.ColumnModel#editor editor} in the {@link Ext.grid.Column column configuration}.</p>
21 * <p>Editability of columns may be controlled programatically by inserting an implementation
22 * of {@link Ext.grid.ColumnModel#isCellEditable isCellEditable} into the
23 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
24 * <p>Editing is performed on the value of the <i>field</i> specified by the column's
25 * <tt>{@link Ext.grid.ColumnModel#dataIndex dataIndex}</tt> in the backing {@link Ext.data.Store Store}
26 * (so if you are using a {@link Ext.grid.ColumnModel#setRenderer renderer} in order to display
27 * transformed data, this must be accounted for).</p>
28 * <p>If a value-to-description mapping is used to render a column, then a {@link Ext.form.Field#ComboBox ComboBox}
29 * which uses the same {@link Ext.form.Field#valueField value}-to-{@link Ext.form.Field#displayFieldField description}
30 * mapping would be an appropriate editor.</p>
31 * If there is a more complex mismatch between the visible data in the grid, and the editable data in
32 * the {@link Edt.data.Store Store}, then code to transform the data both before and after editing can be
33 * injected using the {@link #beforeedit} and {@link #afteredit} events.
35 * @param {Object} config The config object
38 Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
39 <div id="cfg-Ext.grid.EditorGridPanel-clicksToEdit"></div>/**
40 * @cfg {Number} clicksToEdit
41 * <p>The number of clicks on a cell required to display the cell's editor (defaults to 2).</p>
42 * <p>Setting this option to 'auto' means that mousedown <i>on the selected cell</i> starts
43 * editing that cell.</p>
47 <div id="cfg-Ext.grid.EditorGridPanel-forceValidation"></div>/**
48 * @cfg {Boolean} forceValidation
49 * True to force validation even if the value is unmodified (defaults to false)
51 forceValidation: false,
58 <div id="cfg-Ext.grid.EditorGridPanel-autoEncode"></div>/**
59 * @cfg {Boolean} autoEncode
60 * True to automatically HTML encode and decode values pre and post edit (defaults to false)
64 <div id="cfg-Ext.grid.EditorGridPanel-trackMouseOver"></div>/**
65 * @cfg {Boolean} trackMouseOver @hide
68 trackMouseOver: false, // causes very odd FF errors
71 initComponent : function(){
72 Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
75 <div id="cfg-Ext.grid.EditorGridPanel-selModel"></div>/**
76 * @cfg {Object} selModel Any subclass of AbstractSelectionModel that will provide the selection model for
77 * the grid (defaults to {@link Ext.grid.CellSelectionModel} if not specified).
79 this.selModel = new Ext.grid.CellSelectionModel();
82 this.activeEditor = null;
85 <div id="event-Ext.grid.EditorGridPanel-beforeedit"></div>/**
87 * Fires before cell editing is triggered. The edit event object has the following properties <br />
88 * <ul style="padding:5px;padding-left:16px;">
89 * <li>grid - This grid</li>
90 * <li>record - The record being edited</li>
91 * <li>field - The field name being edited</li>
92 * <li>value - The value for the field being edited.</li>
93 * <li>row - The grid row index</li>
94 * <li>column - The grid column index</li>
95 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
97 * @param {Object} e An edit event (see above for description)
100 <div id="event-Ext.grid.EditorGridPanel-afteredit"></div>/**
102 * Fires after a cell is edited. The edit event object has the following properties <br />
103 * <ul style="padding:5px;padding-left:16px;">
104 * <li>grid - This grid</li>
105 * <li>record - The record being edited</li>
106 * <li>field - The field name being edited</li>
107 * <li>value - The value being set</li>
108 * <li>originalValue - The original value for the field, before the edit.</li>
109 * <li>row - The grid row index</li>
110 * <li>column - The grid column index</li>
114 grid.on('afteredit', afterEdit, this );
116 function afterEdit(e) {
117 // execute an XHR to send/commit data to the server, in callback do (if successful):
121 * @param {Object} e An edit event (see above for description)
124 <div id="event-Ext.grid.EditorGridPanel-validateedit"></div>/**
125 * @event validateedit
126 * Fires after a cell is edited, but before the value is set in the record. Return false
127 * to cancel the change. The edit event object has the following properties <br />
128 * <ul style="padding:5px;padding-left:16px;">
129 * <li>grid - This grid</li>
130 * <li>record - The record being edited</li>
131 * <li>field - The field name being edited</li>
132 * <li>value - The value being set</li>
133 * <li>originalValue - The original value for the field, before the edit.</li>
134 * <li>row - The grid row index</li>
135 * <li>column - The grid column index</li>
136 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
138 * Usage example showing how to remove the red triangle (dirty record indicator) from some
139 * records (not all). By observing the grid's validateedit event, it can be cancelled if
140 * the edit occurs on a targeted row (for example) and then setting the field's new value
141 * in the Record directly:
143 grid.on('validateedit', function(e) {
146 if (e.row == myTargetRow) {
148 e.record.data[e.field] = e.value;
152 * @param {Object} e An edit event (see above for description)
159 initEvents : function(){
160 Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
162 this.getGridEl().on('mousewheel', this.stopEditing.createDelegate(this, [true]), this);
163 this.on('columnresize', this.stopEditing, this, [true]);
165 if(this.clicksToEdit == 1){
166 this.on("cellclick", this.onCellDblClick, this);
168 var view = this.getView();
169 if(this.clicksToEdit == 'auto' && view.mainBody){
170 view.mainBody.on('mousedown', this.onAutoEditClick, this);
172 this.on('celldblclick', this.onCellDblClick, this);
176 onResize : function(){
177 Ext.grid.EditorGridPanel.superclass.onResize.apply(this, arguments);
178 var ae = this.activeEditor;
179 if(this.editing && ae){
185 onCellDblClick : function(g, row, col){
186 this.startEditing(row, col);
190 onAutoEditClick : function(e, t){
194 var row = this.view.findRowIndex(t),
195 col = this.view.findCellIndex(t);
196 if(row !== false && col !== false){
198 if(this.selModel.getSelectedCell){ // cell sm
199 var sc = this.selModel.getSelectedCell();
200 if(sc && sc[0] === row && sc[1] === col){
201 this.startEditing(row, col);
204 if(this.selModel.isSelected(row)){
205 this.startEditing(row, col);
212 onEditComplete : function(ed, value, startValue){
213 this.editing = false;
214 this.lastActiveEditor = this.activeEditor;
215 this.activeEditor = null;
218 field = this.colModel.getDataIndex(ed.col);
219 value = this.postEditValue(value, startValue, r, field);
220 if(this.forceValidation === true || String(value) !== String(startValue)){
225 originalValue: startValue,
231 if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){
232 r.set(field, e.value);
234 this.fireEvent("afteredit", e);
237 this.view.focusCell(ed.row, ed.col);
240 <div id="method-Ext.grid.EditorGridPanel-startEditing"></div>/**
241 * Starts editing the specified for the specified row/column
242 * @param {Number} rowIndex
243 * @param {Number} colIndex
245 startEditing : function(row, col){
247 if(this.colModel.isCellEditable(col, row)){
248 this.view.ensureVisible(row, col, true);
249 var r = this.store.getAt(row),
250 field = this.colModel.getDataIndex(col),
255 value: r.data[field],
260 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
262 var ed = this.colModel.getCellEditor(col, row);
267 ed.parentEl = this.view.getEditorParent(ed);
272 c.field.focus(false, true);
277 specialkey: function(field, e){
278 this.getSelectionModel().onEditorKey(field, e);
280 complete: this.onEditComplete,
281 canceledit: this.stopEditing.createDelegate(this, [true])
293 this.activeEditor = ed;
294 // Set the selectSameEditor flag if we are reusing the same editor again and
295 // need to prevent the editor from firing onBlur on itself.
296 ed.selectSameEditor = (this.activeEditor == this.lastActiveEditor);
297 var v = this.preEditValue(r, field);
298 ed.startEdit(this.view.getCell(row, col).firstChild, Ext.isDefined(v) ? v : '');
300 // Clear the selectSameEditor flag
302 delete ed.selectSameEditor;
309 preEditValue : function(r, field){
310 var value = r.data[field];
311 return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlDecode(value) : value;
315 postEditValue : function(value, originalValue, r, field){
316 return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlEncode(value) : value;
319 <div id="method-Ext.grid.EditorGridPanel-stopEditing"></div>/**
320 * Stops any active editing
321 * @param {Boolean} cancel (optional) True to cancel any changes
323 stopEditing : function(cancel){
325 // Store the lastActiveEditor to check if it is changing
326 var ae = this.lastActiveEditor = this.activeEditor;
328 ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
329 this.view.focusCell(ae.row, ae.col);
331 this.activeEditor = null;
333 this.editing = false;
336 Ext.reg('editorgrid', Ext.grid.EditorGridPanel);</pre>