Overview
Set editingMode in useDataGrid to cell or row to enable editing. Only one cell or row
can be edited at a time. Cells of accessor columns are editable unless meta.disableEditing is set.
Editing is not available in list view.
Cell editing
Set editingMode: 'cell' to edit one cell at a time. Double-click a cell to open its editor,
or set editTrigger: 'click' to open it with a single click. Press Enter to save and Escape to cancel,
the value is also saved when the editor loses focus. onEditSave is called with the updated row:
Row editing
Set editingMode: 'row' to edit all editable cells of a row at once. Editing starts
with a double-click on a cell or from an actions column. Enter or a click
outside the row saves it, Escape cancels editing:
Actions column
Add a display column with meta.type: 'actions' to render row action buttons. In its cell,
use row.getIsEditing() to switch between Edit and Save / Cancel buttons and call
row.startEditing(), row.saveEditing() and row.cancelEditing() when they are clicked.
Pass size={store.getControlSize()} to your buttons so they match the grid size:
Floating actions
Set withFloatingEditActions on DataGrid to display floating Save and Cancel buttons
next to the row being edited. It works in row mode only. Use saveRow and cancelRow labels
to change the button text:
Keyboard
Custom editors receive onSave and onCancel and decide which keys call them.
When editing ends, focus returns to the row.
Editing options
useDataGrid accepts the following editing options:
newRow is the row with changed values applied. Dot paths are supported:
accessorKey: 'address.city' updates newRow.address.city. For columns defined with accessorFn,
the new value is written to newRow[column.id].
Async saves
Return a promise from onEditSave to keep the editor open while the save is pending.
If the promise is rejected, onEditSaveError is called and the editor stays open:
In custom editors, use cell.row.getIsSaving() to disable the input while the save is pending.
Validation
Add meta.validate to a column to validate the value before it is saved. The function receives
the value and the row and returns an error message, or null if the value is valid.
The error is displayed in a tooltip and the value cannot be saved until it is changed:
Cell status
Use getCellStatus to highlight cells that are not being edited.
Return dirty for unsaved changes, invalid for invalid values or undefined for the default appearance.
The following example marks empty email cells as invalid:
Custom edit components
Set meta.editComponent on a column to replace the default text input. The component receives
the following props:
valueandonChange– the current value and a function to change itonSaveandonCancel– functions to save the value and to cancel editingerror– validation errorcell– the cell being edited
To save the value as soon as an option is picked, call onSave in onChange:
Disabling editing per column
Set meta.disableEditing: true on a column definition to make the column read-only:
Utility columns, display columns and the actions column are never editable.
Imperative API and controlled state
The editing state is available as store.getEditing() and can be controlled with editing
and onEditingChange. The table, rows and cells have the following methods:
When editing of another row or cell is started, the current one is saved first. If it cannot be saved, the new one is not opened.
Modal editing
For complex edit forms, use onRowDoubleClick to open a modal instead of inline editing: