4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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> * @class Ext.grid.plugin.RowEditing
20 * @extends Ext.grid.plugin.Editing
22 * The Ext.grid.plugin.RowEditing plugin injects editing at a row level for a Grid. When editing begins,
23 * a small floating dialog will be shown for the appropriate row. Each editable column will show a field
24 * for editing. There is a button to save or cancel all changes for the edit.
26 * The field that will be used for the editor is defined at the
27 * {@link Ext.grid.column.Column#field field}. The editor can be a field instance or a field configuration.
28 * If an editor is not specified for a particular column then that column won't be editable and the value of
29 * the column will be displayed.
31 * The editor may be shared for each column in the grid, or a different one may be specified for each column.
32 * An appropriate field type should be chosen to match the data structure that it will be editing. For example,
33 * to edit a date, it would be useful to specify {@link Ext.form.field.Date} as the editor.
35 * {@img Ext.grid.plugin.RowEditing/Ext.grid.plugin.RowEditing.png Ext.grid.plugin.RowEditing plugin}
39 * Ext.create('Ext.data.Store', {
40 * storeId:'simpsonsStore',
41 * fields:['name', 'email', 'phone'],
43 * {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
44 * {"name":"Bart", "email":"bart@simpsons.com", "phone":"555--222-1234"},
45 * {"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
46 * {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
57 * Ext.create('Ext.grid.Panel', {
59 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
61 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
62 * {header: 'Email', dataIndex: 'email', flex:1,
68 * {header: 'Phone', dataIndex: 'phone'}
70 * selType: 'rowmodel',
72 * Ext.create('Ext.grid.plugin.RowEditing', {
78 * renderTo: Ext.getBody()
81 Ext.define('Ext.grid.plugin.RowEditing', {
82 extend: 'Ext.grid.plugin.Editing',
83 alias: 'plugin.rowediting',
91 <span id='Ext-grid-plugin-RowEditing-cfg-autoCancel'> /**
92 </span> * @cfg {Boolean} autoCancel
93 * `true` to automatically cancel any pending changes when the row editor begins editing a new row.
94 * `false` to force the user to explicitly cancel the pending changes. Defaults to `true`.
99 <span id='Ext-grid-plugin-RowEditing-cfg-clicksToMoveEditor'> /**
100 </span> * @cfg {Number} clicksToMoveEditor
101 * The number of clicks to move the row editor to a new row while it is visible and actively editing another row.
102 * This will default to the same value as {@link Ext.grid.plugin.Editing#clicksToEdit clicksToEdit}.
106 <span id='Ext-grid-plugin-RowEditing-cfg-errorSummary'> /**
107 </span> * @cfg {Boolean} errorSummary
108 * `true` to show a {@link Ext.tip.ToolTip tooltip} that summarizes all validation errors present
109 * in the row editor. Set to `false` to prevent the tooltip from showing. Defaults to `true`.
114 <span id='Ext-grid-plugin-RowEditing-event-beforeedit'> /**
115 </span> * @event beforeedit
116 * Fires before row editing is triggered. The edit event object has the following properties <br />
117 * <ul style="padding:5px;padding-left:16px;">
118 * <li>grid - The grid this editor is on</li>
119 * <li>view - The grid view</li>
120 * <li>store - The grid store</li>
121 * <li>record - The record being edited</li>
122 * <li>row - The grid table row</li>
123 * <li>column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit</li>
124 * <li>rowIdx - The row index that is being edited</li>
125 * <li>colIdx - The column index that initiated the edit</li>
126 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
128 * @param {Ext.grid.plugin.Editing} editor
129 * @param {Object} e An edit event (see above for description)
131 <span id='Ext-grid-plugin-RowEditing-event-edit'> /**
132 </span> * @event edit
133 * Fires after a row is edited. The edit event object has the following properties <br />
134 * <ul style="padding:5px;padding-left:16px;">
135 * <li>grid - The grid this editor is on</li>
136 * <li>view - The grid view</li>
137 * <li>store - The grid store</li>
138 * <li>record - The record being edited</li>
139 * <li>row - The grid table row</li>
140 * <li>column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit</li>
141 * <li>rowIdx - The row index that is being edited</li>
142 * <li>colIdx - The column index that initiated the edit</li>
145 * <pre><code>
146 grid.on('edit', onEdit, this);
149 // execute an XHR to send/commit data to the server, in callback do (if successful):
152 * </code></pre>
153 * @param {Ext.grid.plugin.Editing} editor
154 * @param {Object} e An edit event (see above for description)
156 <span id='Ext-grid-plugin-RowEditing-event-validateedit'> /**
157 </span> * @event validateedit
158 * Fires after a cell is edited, but before the value is set in the record. Return false
159 * to cancel the change. The edit event object has the following properties <br />
160 * <ul style="padding:5px;padding-left:16px;">
161 * <li>grid - The grid this editor is on</li>
162 * <li>view - The grid view</li>
163 * <li>store - The grid store</li>
164 * <li>record - The record being edited</li>
165 * <li>row - The grid table row</li>
166 * <li>column - The grid {@link Ext.grid.column.Column Column} defining the column that initiated the edit</li>
167 * <li>rowIdx - The row index that is being edited</li>
168 * <li>colIdx - The column index that initiated the edit</li>
169 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
171 * Usage example showing how to remove the red triangle (dirty record indicator) from some
172 * records (not all). By observing the grid's validateedit event, it can be cancelled if
173 * the edit occurs on a targeted row (for example) and then setting the field's new value
174 * in the Record directly:
175 * <pre><code>
176 grid.on('validateedit', function(e) {
179 if (e.rowIdx == myTargetRow) {
181 e.record.data[e.field] = e.value;
184 * </code></pre>
185 * @param {Ext.grid.plugin.Editing} editor
186 * @param {Object} e An edit event (see above for description)
189 constructor: function() {
191 me.callParent(arguments);
193 if (!me.clicksToMoveEditor) {
194 me.clicksToMoveEditor = me.clicksToEdit;
197 me.autoCancel = !!me.autoCancel;
200 <span id='Ext-grid-plugin-RowEditing-method-destroy'> /**
202 * AbstractComponent calls destroy on all its plugins at destroy time.
204 destroy: function() {
206 Ext.destroy(me.editor);
207 me.callParent(arguments);
210 <span id='Ext-grid-plugin-RowEditing-method-startEdit'> /**
211 </span> * Start editing the specified record, using the specified Column definition to define which field is being edited.
212 * @param {Model} record The Store data record which backs the row to be edited.
213 * @param {Model} columnHeader The Column object defining the column to be edited.
216 startEdit: function(record, columnHeader) {
218 editor = me.getEditor();
220 if (me.callParent(arguments) === false) {
224 // Fire off our editor
225 if (editor.beforeEdit() !== false) {
226 editor.startEdit(me.context.record, me.context.column);
231 cancelEdit: function() {
235 me.getEditor().cancelEdit();
236 me.callParent(arguments);
241 completeEdit: function() {
244 if (me.editing && me.validateEdit()) {
246 me.fireEvent('edit', me.context);
251 validateEdit: function() {
253 return me.callParent(arguments) && me.getEditor().completeEdit();
257 getEditor: function() {
261 me.editor = me.initEditor();
267 initEditor: function() {
271 headerCt = grid.headerCt;
273 return Ext.create('Ext.grid.RowEditor', {
274 autoCancel: me.autoCancel,
275 errorSummary: me.errorSummary,
276 fields: headerCt.getGridColumns(),
279 // keep a reference..
286 initEditTriggers: function() {
290 headerCt = grid.headerCt,
291 moveEditorEvent = me.clicksToMoveEditor === 1 ? 'click' : 'dblclick';
293 me.callParent(arguments);
295 if (me.clicksToMoveEditor !== me.clicksToEdit) {
296 me.mon(view, 'cell' + moveEditorEvent, me.moveEditorByClick, me);
299 view.on('render', function() {
303 remove: me.onColumnRemove,
304 columnresize: me.onColumnResize,
305 columnhide: me.onColumnHide,
306 columnshow: me.onColumnShow,
307 columnmove: me.onColumnMove,
310 }, me, { single: true });
313 startEditByClick: function() {
315 if (!me.editing || me.clicksToMoveEditor === me.clicksToEdit) {
316 me.callParent(arguments);
320 moveEditorByClick: function() {
323 me.superclass.startEditByClick.apply(me, arguments);
328 onColumnAdd: function(ct, column) {
329 if (column.isHeader) {
333 me.initFieldAccessors(column);
334 editor = me.getEditor();
336 if (editor && editor.onColumnAdd) {
337 editor.onColumnAdd(column);
343 onColumnRemove: function(ct, column) {
344 if (column.isHeader) {
346 editor = me.getEditor();
348 if (editor && editor.onColumnRemove) {
349 editor.onColumnRemove(column);
351 me.removeFieldAccessors(column);
356 onColumnResize: function(ct, column, width) {
357 if (column.isHeader) {
359 editor = me.getEditor();
361 if (editor && editor.onColumnResize) {
362 editor.onColumnResize(column, width);
368 onColumnHide: function(ct, column) {
369 // no isHeader check here since its already a columnhide event.
371 editor = me.getEditor();
373 if (editor && editor.onColumnHide) {
374 editor.onColumnHide(column);
379 onColumnShow: function(ct, column) {
380 // no isHeader check here since its already a columnshow event.
382 editor = me.getEditor();
384 if (editor && editor.onColumnShow) {
385 editor.onColumnShow(column);
390 onColumnMove: function(ct, column, fromIdx, toIdx) {
391 // no isHeader check here since its already a columnmove event.
393 editor = me.getEditor();
395 if (editor && editor.onColumnMove) {
396 editor.onColumnMove(column, fromIdx, toIdx);
401 setColumnField: function(column, field) {
403 me.callParent(arguments);
404 me.getEditor().setField(column.field, column);