Enable Editing
To enable Cell Editing for a Column use the editable
property on the Column Definition.
Set to true if this column is editable, otherwise false . Can also be a function to have different rows editable. |
<ag-grid-vue
:columnDefs="columnDefs"
/* other grid options ... */>
</ag-grid-vue>
this.columnDefs = [
{
field: 'athlete',
// enables editing
editable: true
}
];
By default, the grid uses Cell Data Types to provide different editors based on the type of each column. For example, string columns will use a text input, number columns will use a numeric input.
The example below shows editing enabled on all columns by setting editable=true
on the defaultColDef
.
Conditional Editing
To dynamically determine which cells are editable, a callback function can be supplied to the editable
property on the Column Definition:
<ag-grid-vue
:columnDefs="columnDefs"
/* other grid options ... */>
</ag-grid-vue>
this.columnDefs = [
{
field: 'athlete',
// conditionally enables editing for data for 2012
editable: (params) => params.data.year == 2012
}
];
In the snippet above, Athlete cells will be editable on rows where the Year is 2012
.
This is demonstrated in the following example, note that:
- An
editable
callback is added to the Athlete and Age columns to control which cells are editable based on the selected Year. - A custom
editableColumn
Column Type is used to avoid duplication of the callback for Athlete and Age. - Buttons are provided to change the Year used by the
editable
callback function to control which cells are editable. - A blue Cell Style has been added to highlight editable cells using the same logic as the
editable
callback.
Editing Events
Cell editing results in the following events.
Value has changed after editing (this event will not fire if editing was cancelled, eg ESC was pressed) or
if cell value has changed as a result of cut, paste, cell clear (pressing Delete key),
fill handle, copy range down, undo and redo. |
Value has changed after editing. Only fires when readOnlyEdit=true . |
Editing a cell has started. |
Editing a cell has stopped. |
Editing a row has started (when row editing is enabled). When row editing, this event will be fired once and cellEditingStarted will be fired for each individual cell. Only fires when doing Full Row Editing. |
Editing a row has stopped (when row editing is enabled). When row editing, this event will be fired once and cellEditingStopped will be fired for each individual cell. Only fires when doing Full Row Editing. |