4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-grid-plugin-RowEditing'>/**
19 </span> * The Ext.grid.plugin.RowEditing plugin injects editing at a row level for a Grid. When editing begins,
20 * a small floating dialog will be shown for the appropriate row. Each editable column will show a field
21 * for editing. There is a button to save or cancel all changes for the edit.
23 * The field that will be used for the editor is defined at the
24 * {@link Ext.grid.column.Column#editor editor}. The editor can be a field instance or a field configuration.
25 * If an editor is not specified for a particular column then that column won't be editable and the value of
26 * the column will be displayed.
28 * The editor may be shared for each column in the grid, or a different one may be specified for each column.
29 * An appropriate field type should be chosen to match the data structure that it will be editing. For example,
30 * to edit a date, it would be useful to specify {@link Ext.form.field.Date} as the editor.
33 * Ext.create('Ext.data.Store', {
34 * storeId:'simpsonsStore',
35 * fields:['name', 'email', 'phone'],
37 * {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
38 * {"name":"Bart", "email":"bart@simpsons.com", "phone":"555--222-1234"},
39 * {"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
40 * {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
44 * Ext.create('Ext.grid.Panel', {
46 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
48 * {header: 'Name', dataIndex: 'name', editor: 'textfield'},
49 * {header: 'Email', dataIndex: 'email', flex:1,
55 * {header: 'Phone', dataIndex: 'phone'}
57 * selType: 'rowmodel',
59 * Ext.create('Ext.grid.plugin.RowEditing', {
65 * renderTo: Ext.getBody()
68 Ext.define('Ext.grid.plugin.RowEditing', {
69 extend: 'Ext.grid.plugin.Editing',
70 alias: 'plugin.rowediting',
78 <span id='Ext-grid-plugin-RowEditing-cfg-autoCancel'> /**
79 </span> * @cfg {Boolean} autoCancel
80 * True to automatically cancel any pending changes when the row editor begins editing a new row.
81 * False to force the user to explicitly cancel the pending changes. Defaults to true.
85 <span id='Ext-grid-plugin-RowEditing-cfg-clicksToMoveEditor'> /**
86 </span> * @cfg {Number} clicksToMoveEditor
87 * The number of clicks to move the row editor to a new row while it is visible and actively editing another row.
88 * This will default to the same value as {@link Ext.grid.plugin.Editing#clicksToEdit clicksToEdit}.
91 <span id='Ext-grid-plugin-RowEditing-cfg-errorSummary'> /**
92 </span> * @cfg {Boolean} errorSummary
93 * True to show a {@link Ext.tip.ToolTip tooltip} that summarizes all validation errors present
94 * in the row editor. Set to false to prevent the tooltip from showing. Defaults to true.
98 <span id='Ext-grid-plugin-RowEditing-event-beforeedit'> /**
99 </span> * @event beforeedit
100 * Fires before row editing is triggered.
102 * @param {Ext.grid.plugin.Editing} editor
103 * @param {Object} e An edit event with the following properties:
105 * - grid - The grid this editor is on
106 * - view - The grid view
107 * - store - The grid store
108 * - record - The record being edited
109 * - row - The grid table row
110 * - column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit
111 * - rowIdx - The row index that is being edited
112 * - colIdx - The column index that initiated the edit
113 * - cancel - Set this to true to cancel the edit or return false from your handler.
116 <span id='Ext-grid-plugin-RowEditing-event-canceledit'> /**
117 </span> * @event canceledit
118 * Fires when the user has started editing a row but then cancelled the edit
119 * @param {Object} grid The grid
122 <span id='Ext-grid-plugin-RowEditing-event-edit'> /**
123 </span> * @event edit
124 * Fires after a row is edited. Usage example:
126 * grid.on('edit', function(editor, e) {
127 * // commit the changes right after editing finished
131 * @param {Ext.grid.plugin.Editing} editor
132 * @param {Object} e An edit event with the following properties:
134 * - grid - The grid this editor is on
135 * - view - The grid view
136 * - store - The grid store
137 * - record - The record being edited
138 * - row - The grid table row
139 * - column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit
140 * - rowIdx - The row index that is being edited
141 * - colIdx - The column index that initiated the edit
143 <span id='Ext-grid-plugin-RowEditing-event-validateedit'> /**
144 </span> * @event validateedit
145 * Fires after a cell is edited, but before the value is set in the record. Return false to cancel the change. The
146 * edit event object has the following properties
148 * Usage example showing how to remove the red triangle (dirty record indicator) from some records (not all). By
149 * observing the grid's validateedit event, it can be cancelled if the edit occurs on a targeted row (for example)
150 * and then setting the field's new value in the Record directly:
152 * grid.on('validateedit', function(editor, e) {
153 * var myTargetRow = 6;
155 * if (e.rowIdx == myTargetRow) {
157 * e.record.data[e.field] = e.value;
161 * @param {Ext.grid.plugin.Editing} editor
162 * @param {Object} e An edit event with the following properties:
164 * - grid - The grid this editor is on
165 * - view - The grid view
166 * - store - The grid store
167 * - record - The record being edited
168 * - row - The grid table row
169 * - column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit
170 * - rowIdx - The row index that is being edited
171 * - colIdx - The column index that initiated the edit
172 * - cancel - Set this to true to cancel the edit or return false from your handler.
175 constructor: function() {
177 me.callParent(arguments);
179 if (!me.clicksToMoveEditor) {
180 me.clicksToMoveEditor = me.clicksToEdit;
183 me.autoCancel = !!me.autoCancel;
186 <span id='Ext-grid-plugin-RowEditing-method-destroy'> /**
188 * AbstractComponent calls destroy on all its plugins at destroy time.
190 destroy: function() {
192 Ext.destroy(me.editor);
193 me.callParent(arguments);
196 <span id='Ext-grid-plugin-RowEditing-method-startEdit'> /**
197 </span> * Starts editing the specified record, using the specified Column definition to define which field is being edited.
198 * @param {Ext.data.Model} record The Store data record which backs the row to be edited.
199 * @param {Ext.data.Model} columnHeader The Column object defining the column to be edited. @override
201 startEdit: function(record, columnHeader) {
203 editor = me.getEditor();
205 if (me.callParent(arguments) === false) {
209 // Fire off our editor
210 if (editor.beforeEdit() !== false) {
211 editor.startEdit(me.context.record, me.context.column);
216 cancelEdit: function() {
220 me.getEditor().cancelEdit();
221 me.callParent(arguments);
223 me.fireEvent('canceledit', me.context);
228 completeEdit: function() {
231 if (me.editing && me.validateEdit()) {
233 me.fireEvent('edit', me.context);
238 validateEdit: function() {
241 context = me.context,
242 record = context.record,
247 editor.items.each(function(item) {
250 newValues[name] = item.getValue();
251 originalValues[name] = record.get(name);
255 newValues : newValues,
256 originalValues : originalValues
259 return me.callParent(arguments) && me.getEditor().completeEdit();
263 getEditor: function() {
267 me.editor = me.initEditor();
273 initEditor: function() {
277 headerCt = grid.headerCt;
279 return Ext.create('Ext.grid.RowEditor', {
280 autoCancel: me.autoCancel,
281 errorSummary: me.errorSummary,
282 fields: headerCt.getGridColumns(),
285 // keep a reference..
292 initEditTriggers: function() {
296 headerCt = grid.headerCt,
297 moveEditorEvent = me.clicksToMoveEditor === 1 ? 'click' : 'dblclick';
299 me.callParent(arguments);
301 if (me.clicksToMoveEditor !== me.clicksToEdit) {
302 me.mon(view, 'cell' + moveEditorEvent, me.moveEditorByClick, me);
305 view.on('render', function() {
309 remove: me.onColumnRemove,
310 columnresize: me.onColumnResize,
311 columnhide: me.onColumnHide,
312 columnshow: me.onColumnShow,
313 columnmove: me.onColumnMove,
316 }, me, { single: true });
319 startEditByClick: function() {
321 if (!me.editing || me.clicksToMoveEditor === me.clicksToEdit) {
322 me.callParent(arguments);
326 moveEditorByClick: function() {
329 me.superclass.startEditByClick.apply(me, arguments);
334 onColumnAdd: function(ct, column) {
335 if (column.isHeader) {
339 me.initFieldAccessors(column);
340 editor = me.getEditor();
342 if (editor && editor.onColumnAdd) {
343 editor.onColumnAdd(column);
349 onColumnRemove: function(ct, column) {
350 if (column.isHeader) {
352 editor = me.getEditor();
354 if (editor && editor.onColumnRemove) {
355 editor.onColumnRemove(column);
357 me.removeFieldAccessors(column);
362 onColumnResize: function(ct, column, width) {
363 if (column.isHeader) {
365 editor = me.getEditor();
367 if (editor && editor.onColumnResize) {
368 editor.onColumnResize(column, width);
374 onColumnHide: function(ct, column) {
375 // no isHeader check here since its already a columnhide event.
377 editor = me.getEditor();
379 if (editor && editor.onColumnHide) {
380 editor.onColumnHide(column);
385 onColumnShow: function(ct, column) {
386 // no isHeader check here since its already a columnshow event.
388 editor = me.getEditor();
390 if (editor && editor.onColumnShow) {
391 editor.onColumnShow(column);
396 onColumnMove: function(ct, column, fromIdx, toIdx) {
397 // no isHeader check here since its already a columnmove event.
399 editor = me.getEditor();
401 if (editor && editor.onColumnMove) {
402 editor.onColumnMove(column, fromIdx, toIdx);
407 setColumnField: function(column, field) {
409 me.callParent(arguments);
410 me.getEditor().setField(column.field, column);