New to KendoReactLearn about KendoReact Free.

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.

Enabling Editing

The KendoReact Grid supports editing in two modes:

Using the Built-in State Management for Editing

To enable filtering using the built-in state management mechanism, follow these steps:

  1. Enable the autoProcessData prop to allow the Grid to handle paging automatically.

  2. Set the dataItemKey prop to a unique value field from the data bound to the Grid.

  3. Configure the editable prop of the Grid to enable editing. For example, setting it to { mode: 'incell' } will enable the incell editing.

  4. Assign a function to the onItemChange event of the Grid to handle the item editing.

  5. (Optional) Disable editing for specific columns setting its editable property to false.

  6. (Optional) Set the type of the editor per column using the editor property of the GridColumn component. The built-in editor types are text, date, number and boolean. The usage of each editor for each column depends on the type of the edited data.

The following example demonstrates how to implement editing using the built-in state management of the KendoReact Grid.

Change Theme
Theme
Loading ...

Using the Editing in Controlled Mode

  1. Set the editable prop of the Grid to true and configure its edit property to manage the built-in edit state and track which rows are being edited.

    jsx
    const [edit, setEdit] = React.useState<EditDescriptor>({});
    jsx
    <Grid
        edit={edit}
        editable={{ mode: 'incell' }}
    >
  2. Handle the onEditChange to update the edit state of the Grid internally.

    jsx
    <Grid
        onEditChange={handleEditChange}
    >
    jsx
    const handleEditChange = (event: GridEditChangeEvent) => {
        setEdit(event.edit);
    };
  3. Disable editing for specific columns setting its editable property to false.

    jsx
    <Grid>
        <Column field="ProductID" title="Id" editable={false} />
    </Grid>
  4. Set the type of the editor per column using the editor property of the GridColumn component. The built-in editor types are text, date, number and boolean. 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>
  5. 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 as onItemChange parameters.

    jsx
    <Grid onItemChange={onItemChange}>
    jsx
    const 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:

jsx
<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.

Change Theme
Theme
Loading ...

KendoReact Data Grid Editing APIs