This page discusses the different ways in which Cell Editing can be started and stopped.
Assuming editable=true or editable has a callback that returns true for the Column Definition, editing will start upon any of the following:
enableCellEditingOnBackspace=true grid option.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!"£$%^&*()_+-=[];\'#,./\|<>?:@~{}singleClickEdit that will allow single-click to start editing instead of double-click. Another property suppressClickEdit will prevent both single-click and double-click from starting the edit; use this if you only want to have your own way of starting editing, such as clicking a button in your custom cell renderer.startEditingCell(params) on the grid APIThe grid will stop editing when any of the following happen:
stopEditing (from the params above) gets called by the editor. This is how your cell editor informs the grid to stop editing.stopEditing() on the grid API.The following events are fired when editing is started and stopped.
While editing, if you hit Tab, the editing will stop for the current cell and start on the next cell. If you hold down Shift+Tab, the same will happen except the previous cell will start editing rather than the next. This is in line with editing data in Excel.
The next and previous cells can also be navigated using the API functions api.tabToNextCell() and api.tabToPreviousCell(). Both of these methods will return true if the navigation was successful, otherwise false.
The grid has the following API methods for editing:
If the grid is editing, getEditingCells() returns back details of the editing cell(s). The result is an array of objects. If only one cell is editing (the default) then the array will have one entry. If multiple cells are editing (e.g. Full Row Edit) then the array contains all editing cells.
Below is a code example of using the editing API methods.
// start editing country cell on first row
this.gridApi.startEditingCell({
rowIndex: 0,
colKey: 'country'
});
// stop editing
this.gridApi.stopEditing();
// print details of editing cell
const cellDefs = this.gridApi.getEditingCells();
cellDefs.forEach(cellDef => {
console.log(cellDef.rowIndex);
console.log(cellDef.column.getId());
console.log(cellDef.floating);
});The example below illustrates different parts of the editing API. Each button starts editing the 'Last Name' column of the first row with the following differences:
edit(): Normal editing start.edit(Backspace): Edit as if delete button was pressed (clears contents first).edit('T'): Edit as if 'T' was pressed (places 'T' into cell).edit(top): Edits top pinned row.edit(bottom): Edits bottom pinned row.The example also demonstrates the following buttons for edit navigation:
stop(): Stops editing.next(): Edits the next cell.previous(): Edits the previous cell.Finally, the example also demonstrates querying which cell is editing:
which(): If the grid is editing, prints to the console which cell is in edit mode.By default pressing Enter will start editing on a cell, or stop editing on an editing cell. It will not navigate to the cell below.
To allow consistency with Excel the grid has the following properties:
enterNavigatesVertically: Set to true to have Enter key move focus to the cell below if not editing. The default is Enter key starts editing the currently focused cell.enterNavigatesVerticallyAfterEdit: Set to true to have Enter key move focus to the cell below after Enter is pressed while editing. The default is editing will stop and focus will remain on the editing cell.The example below demonstrates the focus moving down when Enter is pressed.
The default is for the grid to enter editing when you Double-Click on a cell. To change the default so that a single-click starts editing, set the property gridOptions.singleClickEdit = true. This is useful when you want a cell to enter edit mode as soon as you click on it, similar to the experience you get when inside Excel.
It is also possible to define single-click editing on a per-column basis using colDef.singleClickEdit = true.
The grid below has singleClickEdit = true so that editing will start on a cell when you single-click on it.
It is possible to configure the grid so neither Single-Click or Double-Click starts editing. To do this set the property suppressClickEdit=true. This is useful when you want to start the editing in another way, such as including a button in your cell renderer.
The grid below has suppressClickEdit = true so that clicking doesn't started editing. The grid configures a Cell Renderer with a button to start editing.
By default, the grid will not stop editing the currently editing cell when the cell loses focus, unless another cell is clicked on. This means clicking on the grid header, or another part of your application, will not stop editing. This can be bad if, for example, you have a save button, and you need the grid to stop editing before you execute your save function (e.g. you want to make sure the edit is saved into the grid's state).
If you want the grid to stop editing when focus leaves the cell or the grid, set the grid property
stopEditingWhenCellsLoseFocus = true.
The example below shows the editing with stopEditingWhenCellsLoseFocus = true. Notice the following:
Cell Editing can also be performed via Cell Editor Components; please see Cell Editor Components for more information.