RowEdit
This feature allows editing of entire rows in a grid in a docked panel which by default slides out from the right.
By default, the editor is docked to the browser viewport, but it can be configured to be local to the grid.
The input fields are generated from the columns in the grid in the same way as the CellEdit, and the editor is a Panel.
//<code-header>
fiddle.title = 'Row editing';
//</code-header>
// grid with row editing
const grid = new Grid({
appendTo : targetElement,
height : 600,
features : {
// cellEditing is enabled by default, so this is necessary
cellEdit : false,
rowEdit : {
// Dock the editor into the grid's element, not the browser viewport
local : true
}
},
showDirty : true,
tbar : {
items : {
instantUpdate : {
type : 'checkbox',
text : 'Instant Update',
tooltip : 'Update record instantly after editing',
value : false,
onChange : ({ checked }) => {
grid.features.rowEdit.instantUpdate = checked;
}
}
}
},
data : DataGenerator.generateData(5),
columns : [
// basic columns has a TextField as editor by default
{
field : 'name',
text : 'Name',
flex : 1,
// Invoked on final edit of input field, typically after pressing enter or blurring the field.
finalizeCellEdit : ({ value }) => {
// returning true will accept the new value otherwise it shows the return statement as error message
return value.trim().length < 5 ? 'Name should be at least 5 characters' : true;
}
},
// a custom editor can be specified
{
field : 'city',
text : 'City',
flex : 1,
editor : {
type : 'combo',
items : ['Stockholm', 'New York', 'Montreal']
}
},
// column types may specify an editor
// NumberColumn for example uses a NumberField
{
type : 'number',
field : 'score',
text : 'Score',
flex : 1,
finalizeCellEdit : ({ value, record }) => {
// record contains sibling column's data
const { city } = record;
// Perform validation based on a sibling column
if (city === 'Paris' && value > 999) {
return "Score can't be higher than 999 for Paris";
}
return true;
}
},
// specify editor: false to make a column "readonly"
{ type : 'number', field : 'age', text : 'Age (readonly)', flex : 1, readOnly : true }
]
});By default, the editor works in batch mode. Fields are changed, and when the "Save" button is clicked (or the Enter key pressed), the record is updated with all the changes.
The editor can be configured to update the record as soon as a field is changed by setting the
instantUpdate config to true.
Note that the revertOnEscape property of columns is respected, so pressing Escape will revert the field to the value of the field on focus.
Pressing Escape on a field which has not been changed will cancel the edit and close the editor.
To start editing a row, double-click a cell in the row, or press Enter or F2 when a cell is focused.
The start gesture can be configured by setting the triggerEvent config to 'cellClick' or
'cellDblClick'.
Editing can be prevented by setting the ignoreCSSSelector config to a CSS selector which matches elements that should not trigger editing.
Pressing Enter or clicking the "Save" button will save the changes and close the editor. Pressing Escape or clicking the "Cancel" button will close the editor without saving changes.
If instantUpdate is true, the record will be updated as soon as a field is changed (on blur or when
changed by trigger action such as spin up or down in a number or date or time field), so Escape and the
"Cancel" button revert the changes before closing the editor.
Clicking outside the editor will normally cancel the ongoing edit and start a new one on the clicked cell. This can
be prevented by setting the continueEditingOnCellClick config to false.
This feature is disabled by default
Configs
22
Configs
22Other
The Panel instance used as the editor.
The width of the editor. (Or height if side is 'top' or 'bottom').
May be specified as a number of pixels or a CSS length string.
By default, the editor field corresponding to the cell clicked will be focused when starting editing.
Set to false to prevent this. Focus will then go to the first field in the editor.
if autoEdit is true, starting editing by typing will always focus the contextual field in
the editor.
Set to true to update the record as soon as a field is changed.
Configure this as true to dock the editor to the grid's element instead of the browser viewport.
Configure this as true to show a "Revert" button in the editor which reverts any unsynced changes to the record.
This reverts all changes made since the data was loaded or synchronized with the server. This is different to just canceling an ongoing edit. This reverts the record to its loaded state.
The button is only shown when starting an edit on a record which has unsynced changes.
The side of the grid where the editor will be shown.
'start' means the inline-start side.
'end' means the inline-end side.
The name of the field from the record to use when generating the title for the editor.
The default implementation returns "Editing " plus the value of the named field from the editing record.
A function (or the name of a function) which will be called passing the editing record to generate the title for the editor.
The default implementation returns "Editing " (localized according to the current locale) plus the value of the field specified in titleField.
This may be configured if a more sophisticated title is required.
| Parameter | Type | Description |
|---|---|---|
record | Model | The record being edited |
The title for the editor
Misc
Properties
21
Properties
21Common
Class hierarchy
Other
The Panel instance used as the editor.
Functions
32
Functions
32Editing
Cancel editing, hides the editor.
This function is exposed on Grid and can thus be called as grid.cancelEditing(...)
| Parameter | Type | Description |
|---|---|---|
isStarting | Boolean | Pass |
false if the edit could not be canceled due to the beforeCancelRowEdit event being prevented.
Start editing specified row. If no cellContext is given it edits the first visible row.
This function is exposed on Grid and can thus be called as grid.startEditing(...).
| Parameter | Type | Description |
|---|---|---|
cellContext | GridLocationConfig | Cell specified in format { id: 'x', columnId/column/field: 'xxx' }. See getCell for details. |
isAutoEdit | Boolean | Pass |
Resolved promise returnstrue if editing has been started, false if an beforeStart listener
has vetoed the edit.
Other
Finish editing, update the underlying record and hide the editor.
This function is exposed on Grid and can thus be called as grid.finishEditing(...)
Resolved promise returns false if the edit could not be finished due to an input field being invalid
or the beforeFinishRowEdit event was prevented.
Configuration
Events
Misc
Events
10
Events
10Fires on the owning Grid before the row editing is canceled, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be reset to initial values on cancel of editing.
// Adding a listener using the "on" method
rowEdit.on('beforeCancelRowEdit', ({ grid, editorContext }) => {
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Fires on the owning Grid before the row editing is finished, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be updated as soon as a field is changed, so this event
would not prevent the record from being updated, only the editor being hidden.
// Adding a listener using the "on" method
rowEdit.on('beforeFinishRowEdit', ({ grid, editorContext }) => {
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Fires on the owning Grid before editing starts, return false to prevent editing
// Adding a listener using the "on" method
rowEdit.on('beforeStartRowEdit', ({ source, editorContext }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
editorContext | RowEditorContext | Editing context |
Fires on the owning Grid before the row editing is finished, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be updated as soon as a field is changed, so this event
would not prevent the record from being updated, only the editor being hidden.
// Adding a listener using the "on" method
rowEdit.on('finishRowEdit', ({ grid, editorContext }) => {
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Fires on the owning Grid when editing starts
// Adding a listener using the "on" method
rowEdit.on('startRowEdit', ({ source, editorContext }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
editorContext | RowEditorContext | Editing context |
Event handlers
10
Event handlers
10Called on the owning Grid before the row editing is canceled, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be reset to initial values on cancel of editing.
new RowEdit({
onBeforeCancelRowEdit({ grid, editorContext }) {
}
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Called on the owning Grid before the row editing is finished, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be updated as soon as a field is changed, so this event
would not prevent the record from being updated, only the editor being hidden.
new RowEdit({
onBeforeFinishRowEdit({ grid, editorContext }) {
}
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Called on the owning Grid before editing starts, return false to prevent editing
new RowEdit({
onBeforeStartRowEdit({ source, editorContext }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
editorContext | RowEditorContext | Editing context |
Called on the owning Grid before the row editing is finished, return false to signal that the value is invalid and editing should not be finalized.
Note that if instantUpdate is true, the record will be updated as soon as a field is changed, so this event
would not prevent the record from being updated, only the editor being hidden.
new RowEdit({
onFinishRowEdit({ grid, editorContext }) {
}
});| Parameter | Type | Description |
|---|---|---|
grid | Grid | Target grid |
editorContext | RowEditorContext | Editing context |
Called on the owning Grid when editing starts
new RowEdit({
onStartRowEdit({ source, editorContext }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
editorContext | RowEditorContext | Editing context |
Typedefs
3
Typedefs
3Row editing context
| Parameter | Type | Description |
|---|---|---|
editor | Panel | The Panel being used. Will contain an |
column | Column | Target column |
record | Model | Target record |
cell | HTMLElement | Target cell |