# KendoReact Grid Editing Overview

The KendoReact 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:

* [Built-in State Management](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing#using-the-built-in-state-management-for-editing): The Grid manages its own editing state internally.

* [Controlled Mode](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing#using-the-editing-in-controlled-mode): The editing state is externally managed by handling events and updating the state accordingly.

## 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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#onitemchange) event of the Grid to handle the item editing.

5. (Optional) Disable editing for specific columns setting its [editable](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridcolumnprops#editable) property to `false`.

6. (Optional) Set the type of the editor per column using the [`editor`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridcolumnprops#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.

[Demo Source](https://demos.telerik.com/kendo-react-ui/grid/editing-row-click/built-in/func/source.txt)

## Using the Editing in Controlled Mode

1. Set the `editable` prop of the Grid to true and configure its [`edit`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#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](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridcolumnprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridcolumnprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops#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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/griditemchangeevent) 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`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridcolumnprops#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.

[Demo Source](https://demos.telerik.com/kendo-react-ui/grid/editing-row-click/controlled/func/source.txt)

## Optimizing Editing Performance for Large Datasets

When working with large datasets in editable Grids, the traditional approach of searching through arrays to update edited items can cause performance bottlenecks. Each cell edit operation requires iterating through the entire array to find the matching item for updates, which becomes noticeable with datasets containing thousands of items.

The KendoReact Grid provides a [`dataIndex`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/griditemchangeevent#dataindex) property in the [`GridItemChangeEvent`](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/griditemchangeevent) that eliminates this issue by providing direct access to the edited item's position in the data array.

> caption Optimized editing approach using dataIndex

```jsx
const itemChange = (event: GridItemChangeEvent) => {
    if (event.field) {
        // Replace the item at dataIndex instead of searching the whole array.
        setData((data) =>
            data.with(event.dataIndex, { ...event.dataItem, [event.field!]: event.value })
        );
    }
};
```

The following example demonstrates the editing performance difference between both approaches using 50,000 items.

[Demo Source](https://demos.telerik.com/kendo-react-ui/grid/editing-performance-dataindex/func/source.txt)

> For older browser support, you can implement a polyfill for the `Array.with()` method.

## KendoReact Grid Editing APIs

* [Inline editing](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-inline)
* [Inline editing with custom editors](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-custom)
* [In-cell editing](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-in-cell)
* [In-cell editing of all cells](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-all-cell)
* [Editing with external popup form](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-external-form)
* [Editing with external Redux Form](https://www.telerik.com/kendo-react-ui-develop/components/grid/editing/editing-redux-form)

## Suggested Links

* [API Reference of the Grid](https://www.telerik.com/kendo-react-ui-develop/components/grid/api/gridprops)
* [API Index of the Grid](https://www.telerik.com/kendo-react-ui-develop/components/grid/api)
