Skip to content

Commit

Permalink
[docs] Explain the use of _action: 'delete' in processRowUpdate (@…
Browse files Browse the repository at this point in the history
…michelengelen) (#12673)

Signed-off-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com>
Co-authored-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com>
Co-authored-by: Bilal Shafi <bilalshafidev@gmail.com>
  • Loading branch information
3 people committed Apr 4, 2024
1 parent 7d50bff commit 64c40d5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/data/data-grid/editing/editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ The value returned is used later as an argument on a call to `apiRef.current.upd
/>
```

If you want to delete a row from the internal state of the Data Grid, you can return an additional property `_action: 'delete'` in the row object from the `processRowUpdate` callback. This will remove the row from the internal state of the Data Grid.
It is a more performant way to delete a row as compared to updating the [`rows` prop](/x/react-data-grid/row-updates/#the-rows-prop) or using `setRows` API method because `processRowUpdate` uses the [`updateRows`](https://mui.com/x/react-data-grid/row-updates/#the-updaterows-method) under the hood which doesn't cause a full regeneration of the row tree.

```tsx
<DataGrid
{...otherProps}
processRowUpdate={(updatedRow, originalRow) => {
if (shouldDeleteRow(updatedRow)) {
return { ...updatedRow, _action: 'delete' };
}
return updatedRow;
}}
/>
```

In the example above, `shouldDeleteRow` is a function that determines whether a row should be deleted based on the updated row data.
If `shouldDeleteRow` returns `true`, the row will be deleted from the Data Grid's internal state.

### Server-side validation

If you need to cancel the save process on `processRowUpdate`—for instance, when a database validation fails, or the user wants to reject the changes—there are two options:
Expand Down

0 comments on commit 64c40d5

Please sign in to comment.