KendoReact Data Grid Editing Overview
The KendoReact Data Grid enables you to create, update, and delete data records by providing built-in edit
state functionality.
Getting Started with the KendoReact Data Grid Editing
-
Set the
editable
prop of the Grid to true and configure itsedit
property to manage the built-in edit state and track which rows are being edited.jsxconst [edit, setEdit] = React.useState<EditDescriptor>({});
jsx<Grid edit={edit} editable={{ mode: 'incell' }} >
-
Handle the
onEditChange
to update the edit state of the Grid internally.jsx<Grid onEditChange={handleEditChange} >
jsxconst handleEditChange = (event: GridEditChangeEvent) => { setEdit(event.edit); };
-
Disable editing for specific columns setting its editable property to
false
.jsx<Grid> <Column field="ProductID" title="Id" editable={false} /> </Grid>
-
Set the type of the editor per column using the
editor
property of the GridColumn component. The built-in editor types aretext
,date
,number
andboolean
. The usage of each editor for each column depends on the type of the edited data.jsx<Grid> <Column field="ProductName" title="Name" editor="text" /> <Column field="FirstOrderedOn" title="First Ordered" editor="date" /> <Column field="UnitsInStock" title="Units" width="150px" editor="numeric" /> <Column field="Discontinued" title="Discontinued" editor="boolean" /> </Grid>
-
Define a function for the
onItemChange
event which will handle the data changes during editing. The event provides the edited data item, the field being changed, and the new value available asonItemChange
parameters.jsx<Grid onItemChange={onItemChange}>
jsxconst itemChange = (event: GridItemChangeEvent) => { if (event.field) { setData((data) => data.map((item) => item.ProductID === event.dataItem.ProductID ? { ...item, [event.field!]: event.value } : item ) ); } setChanges(true); };
Preventing column editing
To prevent a column from being editable, set the editable
prop to false
for the required column:
<Column field="ProductID" title="Id" width="50px" editable={false} />
The following example demonstrates how to implement the editing of the Grid data. Click the Add New button to add a new record at the end of the Grid, and the Cancel one to dismiss the active editing.
KendoReact Data Grid Editing APIs
- Inline editing
- Inline editing with custom editors
- In-cell editing
- In-cell editing of all cells
- Editing with external popup form
- Editing with external Redux Form