Skip to content

Data Grid - Editing recipes

Advanced grid customization recipes.

Multiline editing

You can have columns with multiline text and edit them by creating a custom edit component.

In the demo below, the Bio column is composed of multiple lines. To persist the changes, use Ctrl+Enter (or ⌘ Command+Enter on macOS).

ID
Name
Age
Bio
0
@uvdu
36
Nullam cursus tincidunt auctor.
1
@sar
47
Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Fusce facilisis egestas massa, et eleifend magna imperdiet et. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
2
@lolac
42
Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Pellentesque ac metus velit. Pellentesque ac metus velit. Pellentesque ac metus velit.
3
@ca
58
Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Nam ullamcorper ligula id consectetur auctor. Pellentesque ac metus velit. Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Phasellus et ultrices dui.
4
@erjelvud
70
Nullam cursus tincidunt auctor. Nulla venenatis justo non felis vulputate, eu mollis metus ornare.
5
@dimo
68
Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Fusce facilisis egestas massa, et eleifend magna imperdiet et. Pellentesque ac metus velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
6
@hor
60
Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet.
Total Rows: 50

Conditional validation

When all cells in a row are in edit mode, you can validate fields by comparing their values against one another. To do this, start by adding the preProcessEditCellProps as explained in the validation section. When the callback is called, it will have an additional otherFieldsProps param containing the props from the other fields in the same row. Use this param to check if the value from the current column is valid or not. Return the modified props containing the error as you would for cell editing. Once at the least one field has the error attribute set to a truthy value, the row will not exit edit mode.

The following demo requires a value for the Payment method column only if the Is paid? column is checked:

Expense
Price
Due at
Is paid?
Payment method
Light bill
985.46
7/8/2021
no
Rent
681.62
8/1/2021
no
Car insurance
618.34
8/4/2021
yes
Wire transfer

Rows per page:

1–3 of 3

Linked fields

The options available for one field may depend on the value of another field. For instance, if the singleSelect column is used, you can provide a function to valueOptions returning the relevant options for the value selected in another field, as exemplified below.

const columns: GridColDef[] = [
  {
    field: 'account',
    type: 'singleSelect',
    valueOptions: ({ row }) => {
      if (!row) {
        // The row is not available when filtering this column
        return ['Sales', 'Investments', 'Ads', 'Taxes', 'Payroll', 'Utilities'];
      }

      return row.type === 'Income' // Gets the value of the "type" field
        ? ['Sales', 'Investments', 'Ads']
        : ['Taxes', 'Payroll', 'Utilities'];
    },
  },
];

The code above is already enough to display different options in the Account column based on the value selected in the Type column. The only task left is to reset the account once the type is changed. This is needed because the previously selected account will not exist now in the options. To solve that, you can create a custom edit component, reusing the built-in one, and pass a function to the onValueChange prop. This function should call apiRef.current.setEditCellValue to reset the value of the other field.

const CustomTypeEditComponent = (props: GridEditSingleSelectCellProps) => {
  const apiRef = useGridApiContext();

  const handleValueChange = async () => {
    await apiRef.current.setEditCellValue({
      id: props.id,
      field: 'account',
      value: '',
    });
  };

  return <GridEditSingleSelectCell onValueChange={handleValueChange} {...props} />;
};

The demo below combines the steps showed above. You can experiment it by changing the value of any cell in the Type column. The Account column is automatically updated with the correct options.

Description
Value
Type
Account
Light bill
163.63
Expense
Utilities
Order #5
86.44
Income
Sales
Google AdSense
723.83
Income
Ads

Rows per page:

1–3 of 3

A similar behavior can be reproduced with cell editing. Instead of apiRef.current.setEditCellValue, the rows prop must be updated or apiRef.current.updateRows be used. Note that the onCellEditStart and onCellEditStop props also have to be used to revert the value of the cell changed, in case the user cancels the edit.

Description
Value
Type
Account
Light bill
797.52
Expense
Utilities
Order #5
56.89
Income
Sales
Google AdSense
647.41
Income
Ads

Rows per page:

1–3 of 3

Single click editing

By default, one of the ways to enter the edit mode is by double-clicking a cell. Using the controlled mode and listening to click events, you can also enter the edit mode with just a single click. The following demo implements this behavior.

Name
Age
Date Created
Last Login
Rosetta Bridges
25
9/17/2024
3/28/2025, 12:15:51 AM
Alex Diaz
36
1/15/2025
3/27/2025, 11:54:28 PM
Bertha Carter
19
3/23/2025
3/27/2025, 10:10:54 PM
Jane Mason
28
5/14/2024
3/28/2025, 11:58:09 AM
Lelia Huff
23
9/2/2024
3/28/2025, 8:22:37 AM

Rows per page:

1–5 of 5

Usage with @mui/x-date-pickers

By default, the data grid uses native browser inputs for editing date and dateTime columns.

While MUI X Date / Time Pickers are not supported by the data grid out of the box yet, it is easy to integrate them by creating custom edit components and custom filter operators.

The example below uses @mui/x-date-pickers for both date and dateTime column types:

Name
Age
Date Created
Last Login
Keith Carter
25
02/05/2025
03/28/2025 11:57 AM
Carrie Cortez
36
06/27/2024
03/28/2025 1:19 PM
Jeff Kim
19
02/07/2025
03/27/2025 11:47 PM
Flora Montgomery
28
11/21/2024
03/28/2025 8:16 PM
Alan Quinn
23
06/08/2024
03/28/2025 1:44 AM

Rows per page:

1–5 of 5