This page discusses the different ways in which Cell Editing can be started and stopped.
Assuming editable=True
or editable
has a function that returns True
for the Column Definition, editing will start
upon any of the following:
enableCellEditingOnBackspace=True
on Grid Option.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!"£$%^&*()_+-=[];\'#,./\|<>?:@~{}
singleClickEdit
that will allowsuppressClickEdit
will prevent bothThe grid will stop editing when any of the following happen:
While editing, if you hit <kbd>↹ Tab<kbd> , the editing will stop for the current cell and start on the next cell. If
you hold down <kbd>⇧ Shift<kbd> + <kbd>↹ Tab<kbd>, the same will happen except the previous cell will start editing
rather than the next. This is in line with editing data in Excel.
By default, pressing <kbd>↵ Enter<kbd> 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 <kbd>↵ Enter<kbd> key move focus to the cell below if not editing.enterNavigatesVerticallyAfterEdit
: Set to True
to have <kbd>↵ Enter<kbd> key move focus to the cell below afterThe example below demonstrates the focus moving down when <kbd>↵ Enter<kbd> 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 Grid Option:
dashGridOptions = {"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 singleClickEdit = True
in
the columnDefs
property.
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 nor Double-Click starts editing. To do this set the Grid
Option:
dashGridOptions = {"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 start editing. The grid configures a Cell
Renderer with a button to start editing.
View Custom Cell Renderer used for this example.
This JavaScript function must be added to the dashAgGridComponentFunctions.js
file in the assets folder.
See Custom Components for more
information.
var dagcomponentfuncs = (window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {});
dagcomponentfuncs.EditButton = function (props) {
function onButtonClicked() {
props.api.startEditingCell({
rowIndex: props.rowIndex,
colKey: props.column.getId(),
});
}
return React.createElement('span', {}, [
React.createElement(
'button',
{onClick: onButtonClicked, style: {padding: 5},},
'✎'
),
React.createElement(
'span',
{style: {paddingLeft: '4px'},},
props.value
),
]);
};
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 (for example, 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 Option:
dashGridOptions = {"stopEditingWhenCellsLoseFocus": True}
The example below shows the editing with stopEditingWhenCellsLoseFocus = True
. Notice the following:
Double-click a cell to start editing, then click outside the grid (or on a header) and the grid will stop editing.
Note that Cell Editing can also be performed via Cell Editor Components: