From 765ba84956904bfc15828075089455ed91ffb428 Mon Sep 17 00:00:00 2001 From: Yasir Assam Date: Thu, 1 Jan 2015 09:38:17 +1100 Subject: [PATCH 1/2] editorArgs function for always-on editors also takes object parameter The Editor mixin specifies a column property editorArgs, which can either be an object or a function returning an object. If it's a function, the function takes a column object as its first parameter. My change was to also pass the row object as the second parameter to editorArgs. This can only be passed for always-on editors, so for shared editors (aka editOn editors) only the column parameter is passed (the object parameter is undefined). I needed to create always-on editors with parameters that depended on the row data, and this is the only way I could see of doing it. For editOn editors it's possible to set up a handler for the dgrid-editor-show event and get the row data that way, but I don't think that event is emitted for always-on editors. --- Editor.js | 12 ++++++++---- doc/components/mixins/Editor.md | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Editor.js b/Editor.js index f6fb5a9b6..77c3f02c8 100644 --- a/Editor.js +++ b/Editor.js @@ -172,7 +172,7 @@ define([ } : function (object, value, cell, options) { // always-on: create editor immediately upon rendering each cell if (!column.canEdit || column.canEdit(object, value)) { - var cmp = self._createEditor(column); + var cmp = self._createEditor(column, object); self._showEditor(cmp, column, cell, value); // Maintain reference for later use. cell[isWidget ? 'widget' : 'input'] = cmp; @@ -356,9 +356,13 @@ define([ } }, - _createEditor: function (column) { + _createEditor: function (column, object) { // Creates an editor instance based on column definition properties, // and hooks up events. + // + // object is undefined when creating a shared editor. For + // an always-on editor, object is the row data. If + // editorArgs is a function, object will be passed to this function var editor = column.editor, editOn = column.editOn, self = this, @@ -367,7 +371,7 @@ define([ args = column.editorArgs || {}; if (typeof args === 'function') { - args = args.call(this, column); + args = args.call(this, column, object); } if (Widget) { @@ -690,4 +694,4 @@ define([ return value; } }); -}); \ No newline at end of file +}); diff --git a/doc/components/mixins/Editor.md b/doc/components/mixins/Editor.md index b160e45b7..087b52bd1 100644 --- a/doc/components/mixins/Editor.md +++ b/doc/components/mixins/Editor.md @@ -44,7 +44,7 @@ Property | Description -------- | ----------- `editor` | The type of component to use for editors in this column; either a string specifying a type of standard HTML input to create, or a Dijit widget constructor to instantiate. If unspecified, the column will not be editable. `editOn` | A string containing the event (or multiple events, comma-separated) upon which the editor should activate. If unspecified, editors are always displayed in this column's cells. -`editorArgs` | An object containing input attributes or widget arguments. For HTML inputs, the object will have its key/value pairs applied as node attributes via `put-selector`; for widgets, the object will be passed to the widget constructor. +`editorArgs` | An object containing input attributes or widget arguments. For HTML inputs, the object will have its key/value pairs applied as node attributes via `put-selector`; for widgets, the object will be passed to the widget constructor. Alternatively, `editorArgs` can be a function returning this object. It should have signature `editorArgs(column, object)`. The `object` parameter is `undefined` for `editOn` editors. `canEdit(object, value)` | A function returning a boolean value indicating whether or not the cell for this column should be editable in a particular row. Receives the item for the current row, and the value to be rendered (i.e. the return from the column's `get` function if any, or the value of the `field` specified in the column). `autoSave` | If `true`, the grid's `save` method will be called as soon as a change is detected in an editor in this column. Defaults to `false`. **Note:** if an error is encountered as a result of a store operation triggered by `autoSave`, a `dgrid-error` event will be emitted. `autoSelect` | If `true` and `editor` is `'text'` or a `TextBox`-based widget, the contents of the field will be selected when the editor is activated/focused. From f1e7dfb26f469daf8f6f25849f0cd099554acbf1 Mon Sep 17 00:00:00 2001 From: Mangala SSS Khalsa Date: Wed, 8 Jan 2020 22:27:19 -0700 Subject: [PATCH 2/2] Editor: update wording in documentation for editorArgs --- Editor.js | 6 ++---- doc/components/mixins/Editor.md | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Editor.js b/Editor.js index 36f74aa4d..cddf29d1a 100644 --- a/Editor.js +++ b/Editor.js @@ -448,10 +448,6 @@ define([ _createEditor: function (column, object) { // Creates an editor instance based on column definition properties, // and hooks up events. - // - // object is undefined when creating a shared editor. For - // an always-on editor, object is the row data. If - // editorArgs is a function, object will be passed to this function var editor = column.editor, editOn = column.editOn, self = this, @@ -464,6 +460,8 @@ define([ args = column.editorArgs || {}; if (typeof args === 'function') { + // `object` is undefined for shared editors, but for always-on + // editors it will be the row data. args = args.call(this, column, object); } diff --git a/doc/components/mixins/Editor.md b/doc/components/mixins/Editor.md index 9306d8931..34eeaf014 100644 --- a/doc/components/mixins/Editor.md +++ b/doc/components/mixins/Editor.md @@ -44,7 +44,7 @@ Property | Description -------- | ----------- `editor` | The type of component to use for editors in this column; either a string specifying a type of standard HTML input to create, or a Dijit widget constructor to instantiate. If unspecified, the column will not be editable. `editOn` | A string containing the event (or multiple events, comma-separated) upon which the editor should activate. If unspecified, editors are always displayed in this column's cells. -`editorArgs` | An object containing input attributes or widget arguments. For HTML inputs, the object will have its key/value pairs applied as attributes/properties via `dojo/dom-construct.create`; for widgets, the object will be passed to the widget constructor. Alternatively, `editorArgs` can be a function returning this object. It should have signature `editorArgs(column, object)`. The `object` parameter is `undefined` for `editOn` editors. +`editorArgs` | An object containing input attributes or widget arguments. For HTML inputs, the object will have its key/value pairs applied as attributes/properties via `dojo/dom-construct.create`; for widgets, the object will be passed to the widget constructor. Alternatively, `editorArgs` can be a function returning this object. It should have the signature `editorArgs(column, rowObject)`. The `rowObject` parameter is only defined for always-on editors. `canEdit(object, value)` | A function returning a boolean value indicating whether or not the cell for this column should be editable in a particular row. Receives the item for the current row, and the value to be rendered (i.e. the return from the column's `get` function if any, or the value of the `field` specified in the column). `autoSave` | If `true`, the grid's `save` method will be called as soon as a change is detected in an editor in this column. Defaults to `false`. **Note:** if an error is encountered as a result of a store operation triggered by `autoSave`, a `dgrid-error` event will be emitted. `autoSelect` | If `true` and `editor` is `'text'` or a `TextBox`-based widget, the contents of the field will be selected when the editor is activated/focused.