4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.grid.EditorGrid
14 * @extends Roo.grid.Grid
15 * Class for creating and editable grid.
16 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
17 * The container MUST have some type of size defined for the grid to fill. The container will be
18 * automatically set to position relative if it isn't already.
19 * @param {Object} dataSource The data model to bind to
20 * @param {Object} colModel The column model with info about this grid's columns
22 Roo.grid.EditorGrid = function(container, config){
23 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
24 this.getGridEl().addClass("xedit-grid");
27 this.selModel = new Roo.grid.CellSelectionModel();
30 this.activeEditor = null;
35 * Fires before cell editing is triggered. The edit event object has the following properties <br />
36 * <ul style="padding:5px;padding-left:16px;">
37 * <li>grid - This grid</li>
38 * <li>record - The record being edited</li>
39 * <li>field - The field name being edited</li>
40 * <li>value - The value for the field being edited.</li>
41 * <li>row - The grid row index</li>
42 * <li>column - The grid column index</li>
43 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
45 * @param {Object} e An edit event (see above for description)
50 * Fires after a cell is edited. <br />
51 * <ul style="padding:5px;padding-left:16px;">
52 * <li>grid - This grid</li>
53 * <li>record - The record being edited</li>
54 * <li>field - The field name being edited</li>
55 * <li>value - The value being set</li>
56 * <li>originalValue - The original value for the field, before the edit.</li>
57 * <li>row - The grid row index</li>
58 * <li>column - The grid column index</li>
60 * @param {Object} e An edit event (see above for description)
65 * Fires after a cell is edited, but before the value is set in the record.
66 * You can use this to modify the value being set in the field, Return false
67 * to cancel the change. The edit event object has the following properties <br />
68 * <ul style="padding:5px;padding-left:16px;">
69 * <li>editor - This editor</li>
70 * <li>grid - This grid</li>
71 * <li>record - The record being edited</li>
72 * <li>field - The field name being edited</li>
73 * <li>value - The value being set</li>
74 * <li>originalValue - The original value for the field, before the edit.</li>
75 * <li>row - The grid row index</li>
76 * <li>column - The grid column index</li>
77 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
79 * @param {Object} e An edit event (see above for description)
83 this.on("bodyscroll", this.stopEditing, this);
84 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
87 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
89 * @cfg {Number} clicksToEdit
90 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
97 trackMouseOver: false, // causes very odd FF errors
99 onCellDblClick : function(g, row, col){
100 this.startEditing(row, col);
103 onEditComplete : function(ed, value, startValue){
104 this.editing = false;
105 this.activeEditor = null;
106 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
108 var field = this.colModel.getDataIndex(ed.col);
113 originalValue: startValue,
120 var cell = Roo.get(this.view.getCell(ed.row,ed.col));
123 if(String(value) !== String(startValue)){
125 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
126 r.set(field, e.value);
127 // if we are dealing with a combo box..
128 // then we also set the 'name' colum to be the displayField
129 if (ed.field.displayField && ed.field.name) {
130 r.set(ed.field.name, ed.field.el.dom.value);
133 delete e.cancel; //?? why!!!
134 this.fireEvent("afteredit", e);
137 this.fireEvent("afteredit", e); // always fire it!
139 this.view.focusCell(ed.row, ed.col);
143 * Starts editing the specified for the specified row/column
144 * @param {Number} rowIndex
145 * @param {Number} colIndex
147 startEditing : function(row, col){
149 if(this.colModel.isCellEditable(col, row)){
150 this.view.ensureVisible(row, col, true);
152 var r = this.dataSource.getAt(row);
153 var field = this.colModel.getDataIndex(col);
154 var cell = Roo.get(this.view.getCell(row,col));
159 value: r.data[field],
164 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
166 var ed = this.colModel.getCellEditor(col, row);
172 ed.render(ed.parentEl || document.body);
178 (function(){ // complex but required for focus issues in safari, ie and opera
182 ed.on("complete", this.onEditComplete, this, {single: true});
183 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
184 this.activeEditor = ed;
185 var v = r.data[field];
186 ed.startEdit(this.view.getCell(row, col), v);
187 // combo's with 'displayField and name set
188 if (ed.field.displayField && ed.field.name) {
189 ed.field.el.dom.value = r.data[ed.field.name];
199 * Stops any active editing
201 stopEditing : function(){
202 if(this.activeEditor){
203 this.activeEditor.completeEdit();
205 this.activeEditor = null;
209 * Called to get grid's drag proxy text, by default returns this.ddText.
212 getDragDropText : function(){
213 var count = this.selModel.getSelectedCell() ? 1 : 0;
214 return String.format(this.ddText, count, count == 1 ? '' : 's');