# Dialog Editing in KendoReact Grid

## Setup the Built-In Dialog Editing

The KendoReact Grid supports external dialog editing, enabling you to edit and manipulate data in outside of the Grid component. Its features are as follows:

1. Set the [`editable`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#editable) prop of the grid to `editable={{ mode: 'dialog', enabled: true }}`.

2. Set the [`dataItemKey`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#dataItemKey) to indicate the key identifier for editing.

3. Configure the [`edit`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#edit) property to manage the built-in edit state. This will notify the Grid when a row is in edit and the external Dialog will pop-up.

```jsx
const dataItemKey = 'ProductID';
const [edit, setEdit] = React.useState<EditDescriptor>({});

<Grid
    edit={edit}
    dataItemKey={dataItemKey}
    editable={{ mode: 'dialog', enabled: true }}
/>
```

4. You can decide the way which the Grid will be notified when a row is in edit mode so that the edit Dialog can show.

```jsx
const rowClick = (event: GridRowClickEvent) => {
    const inEditID = event.dataItem[dataItemKey]

    setEdit({ [inEditID]: true});
};

<Grid
    edit={edit}
    editable={{ mode: 'dialog', enabled: true }}
    onRowClick={rowClick}
/>
```

5. Finally when the editing is finished, handle the new data and update the data state.

```jsx
const handleItemChange = (event: GridItemChangeEvent) => {
    const inEditID = event.dataItem.ProductID;

    const newData = data.map((item) => {
        const isRowEdited = item.ProductID === inEditID;

        return isRowEdited ? { ...item, ...event.dataItem } : item;
    });

    setData(newData);
    // Clear the edit descriptor to close the edit Dialog.
    setEdit({});
};

<Grid
    edit={edit}
    editable={{ mode: 'dialog', enabled: true }}
    dataItemKey={dataItemKey}
    onRowClick={rowClick}
    onItemChange={handleItemChange}
/>
```

Here is an example that showcases how to utilize the external Dialog edit in the KendoReact Grid.

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

## Editing Input Validation

The built-in edit Dialog has a mechanism to validate inputs by utilizing the Grid Column [`validator`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridcolumnprops#validator) prop.

```jsx
const nameValidator = (value: string) => {
    if (value?.length < 3) {
        return 'Name must be at least 3 characters long';
    }

    // Return an empty string when the value is valid.
    return '';
};
<Grid>
    <GridColumn field="ProductName" validator={nameValidator}/>
<Grid/>
```

The following example showcases how the validation of the edit inputs work.

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

## Custom Edit Dialog

You can also cutomize the edit dialog by passing a custom dialog component to the [`editDialog`](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops#editDialog) property of the Grid.

The following example showcases how to pass a custom form dialog component.

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

## Suggested Links

* [Data Query Overview](https://www.telerik.com/kendo-react-ui/components/dataquery)
* [API Reference of the Grid](https://www.telerik.com/kendo-react-ui/components/grid/api/gridprops)
* [API Reference of the GridToolbar](https://www.telerik.com/kendo-react-ui/components/grid/api/gridtoolbar)
* [API Index of the Grid](https://www.telerik.com/kendo-react-ui/components/grid/api)
