New to KendoReactStart a free 30-day trial

Dialog Editing in KendoReact Data Grid
Premium

Setup the Built-In Dialog Editing

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

  1. Set the editable prop of the grid to editable={{ mode: 'dialog', enabled: true }}.

  2. Set the dataItemKey to indicate the key identifier for editing.

  3. Configure the 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 }}
/>
  1. 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}
/>
  1. 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);
    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.

Change Theme
Theme
Loading ...

Editing Input Validation

The built-in edit Dialog has a mechanism to validate inputs by utilizing the Grid Column validator prop.

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

    return '';
};
<Grid>
    <GridColumn field="ProductName" validator={nameValidator}/>
<Grid/>

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

Change Theme
Theme
Loading ...

Custom Edit Dialog

You can also cutomize the edit dialog by passing a custom dialog component to the editDialog property of the Grid.

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

Change Theme
Theme
Loading ...