Skip to content

Commit

Permalink
[docs] Add () for updateRows method (#15251)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Tassinari <[email protected]>
Co-authored-by: Flavien DELANGLE <[email protected]>
  • Loading branch information
oliviertassinari and flaviendelangle authored Nov 7, 2024
1 parent a62b88f commit a202034
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 34 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,9 @@ No changes since `@mui/[email protected]`.

### Docs

- [docs] Add a warning to promote the usage of `updateRows` (#14027) @MBilalShafi
- [docs] Add a warning to promote the usage of `updateRows()` (#14027) @MBilalShafi
- [docs] Disable ad in `Rich Tree View-Ordering` page (#14123) @oliviertassinari
- [docs] Redesign Date and Time Pickers overview page (#13241) @noraleonte

- [CHANGELOG] Polish details @oliviertassinari
- [code-infra] Use concurrency 1 in CircleCI (#14110) @JCQuintas
- [infra] Re-added the removal of `Latest Version` section (#14132) @michelengelen
Expand Down
10 changes: 5 additions & 5 deletions changelogOld/CHANGELOG.v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,23 @@ Big thanks to the 11 contributors who made this release possible. Here are some

- [DataGrid] Improve the editing API (#1955) @m4theushw

- The `props` key in the first argument of `commitCellChange` was removed to promote the use of the value already stored in the state.
To update the value in the state, call `setEditCellProps` before.
- The `props` key in the first argument of `commitCellChange()` was removed to promote the use of the value already stored in the state.
To update the value in the state, call `setEditCellProps()` before.

```diff
-apiRef.current.commitCellChange({ id: 1, field: 'name', props: { value: 'Ana' } });
+apiRef.current.setEditCellProps({ id: 1, field: 'name', props: { value: 'Ana' } });
+apiRef.current.commitCellChange({ id: 1, field: 'name' });
```

- Calling `commitCellChange` in a cell in view mode will throw an error. Make sure to first enter the edit mode.
- Calling `commitCellChange()` in a cell in view mode throws an error. Make sure to first enter the edit mode.

```diff
+apiRef.current.setCellMode(1, 'name', 'edit');
apiRef.current.commitCellChange({ id: 1, field: 'name' });
```

- The `setCellValue` was removed from the API. Use `commitCellChange` or `updateRows` in place.
- The `setCellValue()` was removed from the API. Use `commitCellChange()` or `updateRows()` in place.

```diff
-apiRef.current.setCellValue({ id: 1, field: 'name', value: 'Ana' });
Expand Down Expand Up @@ -1807,7 +1807,7 @@ Big thanks to the 8 contributors who made this release possible. Here are some h
+apiRef.current.setRows()
```

`apiRef.current.updateRowModels` has been removed, please use `apiRef.current.updateRows`.
`apiRef.current.updateRowModels()` has been removed, please use `apiRef.current.updateRows()`.

#### Changes

Expand Down
10 changes: 5 additions & 5 deletions changelogOld/CHANGELOG.v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We'd like to offer a big thanks to the 5 contributors who made this release poss
#### Changes

- [DataGrid] Allow to pass props to the `FocusTrap` inside the panel wrapper (#7897) @Vivek-Prajapatii
- [DataGrid] Avoid unnecessary rerenders after `updateRows` (#7945) @cherniavskii
- [DataGrid] Avoid unnecessary rerenders after `updateRows()` (#7945) @cherniavskii
- [DataGridPro] Change cursor when dragging a column (#7878) @sai6855
- [DataGridPremium] Fix `leafField` to have correct focus value (#7959) @MBilalShafi

Expand Down Expand Up @@ -332,7 +332,7 @@ We'd like to offer a big thanks to the 7 contributors who made this release poss

- [DataGrid] Fix `ErrorOverlay` not receiving defined input props (#6885) @banoth-ravinder
- [DataGrid] Improve typing for `styleOverrides` (#6980) @iigrik
- [DataGridPro] Fix lazy-loaded rows not working with `updateRows` API method (#6875) @cherniavskii
- [DataGridPro] Fix lazy-loaded rows not working with `updateRows()` API method (#6875) @cherniavskii
- [l10n] Fix translation of `filterOperatorBefore` in Arabic (ar-SD) locale (#6917) @HassanGhazy

### `@mui/[email protected]` / `@mui/[email protected]`
Expand Down Expand Up @@ -2184,7 +2184,7 @@ A big thanks to the 9 contributors who made this release possible. Here are some
- [DataGrid] Fix `isRowSelectable` when `paginationMode='server'` (#3647) @flaviendelangle
- [DataGrid] Fix browser keyboard shortcuts not working when header cell is focused (#3692) @valenfv
- [DataGrid] Fix focus on checkbox cells (#3501) @alexfauquette
- [DataGrid] Only update the visibility status of the updated columns when calling `apiRef.current.updateRows` (#3735) @flaviendelangle
- [DataGrid] Only update the visibility status of the updated columns when calling `updateRows()` (#3735) @flaviendelangle
- [DataGrid] Prevent commit if `preProcessEditCellProps` resolves with an error (#3612) @m4theushw
- [DataGrid] Update selected rows when turning off `checkboxSelection` (#3684) @m4theushw
- [DataGrid] Variable row height (#3218) @DanailH
Expand Down Expand Up @@ -2726,10 +2726,10 @@ A big thanks to the 7 contributors who made this release possible. Here are some

#### Changes

- [DataGrid] Block multi-rows updates in `apiRef.current.updateRows` on the Community plan (#3095) @flaviendelangle
- [DataGrid] Block multi-rows updates in `updateRows()` on the Community plan (#3095) @flaviendelangle
- [DataGrid] Fix filter not working after deleting the value (#3018) @m4theushw
- [DataGrid] Fix performance regression when selecting 100k rows (#3077) @m4theushw
- [DataGrid] Fix `apiRef.current.updateRows` to not share rows from other instances (#3127) @m4theushw
- [DataGrid] Fix `updateRows()` to not share rows from other instances (#3127) @m4theushw
- [DataGrid] Fix flex space allocation to not cause a horizontal scroll when there is enough space (#3099) @flaviendelangle
- [DataGrid] Improve the filter panel behaviors (#3080) @flaviendelangle
- [DataGrid] Fix keyboard navigation between column headers and rows when not on the first page (#3086) @flaviendelangle
Expand Down
6 changes: 3 additions & 3 deletions changelogOld/CHANGELOG.v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ We'd like to offer a big thanks to the 7 contributors who made this release poss
- [DataGrid] Fix missing watermark in Pro and Premium packages (#8797) @cherniavskii
- [DataGrid] Remove unwarranted warning log (#8847) @romgrk
- [DataGrid] Add Joy UI slots (`Select`, `SelectOption`, `InputLabel`, `FormControl`) (#8747) @cherniavskii
- [DataGridPremium] Fix expanded groups being collapsed after calling `updateRows` (#8823) @cherniavskii
- [DataGridPremium] Fix expanded groups being collapsed after calling `updateRows()` (#8823) @cherniavskii

### `@mui/[email protected]` / `@mui/[email protected]`

Expand Down Expand Up @@ -3256,7 +3256,7 @@ We'd like to offer a big thanks to the 8 contributors who made this release poss

- [DataGrid] Add interface for `singleSelect` column (#7685) @m4theushw
- [DataGrid] Allow to pass props to the `FocusTrap` inside the panel wrapper (#7733) @ivek-Prajapatii
- [DataGrid] Avoid unnecessary rerenders after `updateRows` (#7857) @cherniavskii
- [DataGrid] Avoid unnecessary rerenders after `updateRows()` (#7857) @cherniavskii
- [DataGridPro] Change cursor when dragging a column (#7725) @sai6855
- [DataGridPremium] Fix `leafField` to have correct focus value (#7950) @MBilalShafi

Expand Down Expand Up @@ -4362,7 +4362,7 @@ We'd like to offer a big thanks to the 14 contributors who made this release pos
- [DataGrid] Stop exporting root base state selectors (#6912) @DanailH
- [DataGrid] Support `theme.vars` (#6784) @alexfauquette
- [DataGrid] Rename `rowsScroll` event to `scrollPositionChange` (#6957) @DanailH
- [DataGridPro] Fix lazy-loaded rows not working with `updateRows` API method (#6976) @cherniavskii
- [DataGridPro] Fix lazy-loaded rows not working with `updateRows()` API method (#6976) @cherniavskii
- [DataGridPremium] Improve typing for theme in `styleOverrides` (#6920) @m4theushw
- [l10n] Fix translation of `filterOperatorBefore` in Arabic (ar-SD) locale (#6884) @HassanGhazy

Expand Down
18 changes: 9 additions & 9 deletions docs/data/data-grid/editing/editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The callback is called with three arguments:
3. An object with additional properties such as `rowId`.

Please note that the `processRowUpdate` must return the row object to update the Data Grid internal state.
The value returned is used later as an argument on a call to `apiRef.current.updateRows`.
The value returned is used later as an argument on a call to `apiRef.current.updateRows()`.

```tsx
<DataGrid
Expand All @@ -176,7 +176,7 @@ 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.
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
Expand Down Expand Up @@ -378,7 +378,7 @@ These are the most important params to consider:
- `isProcessingProps`: whether `preProcessEditCellProps` is being executed or not

Once a new value is entered into the input, it must be sent to the Data Grid.
To do this, pass the row ID, the column field, and the new cell value to a call to `apiRef.current.setEditCellValue`.
To do this, pass the row ID, the column field, and the new cell value to a call to `apiRef.current.setEditCellValue()`.
The new value will be parsed and validated, and the `value` prop will reflect the changes in the next render.

It's important to also handle the [accessibility](/x/react-data-grid/accessibility/) of custom edit components.
Expand Down Expand Up @@ -413,17 +413,17 @@ The following demo implements a custom edit component, based on the [`Rating`](h

### With debounce

By default, each call to `apiRef.current.setEditCellValue` triggers a new render.
By default, each call to `apiRef.current.setEditCellValue()` triggers a new render.
If the edit component requires the user to type a new value, re-rendering the Data Grid too often will drastically reduce performance.
One way to avoid this is to debounce the API calls.
You can use `apiRef.current.setEditCellValue` to handle debouncing by setting the `debounceMs` param to a positive integer that defines a set time period in milliseconds.
You can use `apiRef.current.setEditCellValue()` to handle debouncing by setting the `debounceMs` param to a positive integer that defines a set time period in milliseconds.
No matter how many times the API method is called, the Data Grid will only be re-rendered after that period of time has passed.

```tsx
apiRef.current.setEditCellValue({ id, field, value: newValue, debounceMs: 200 });
```

When the Data Grid is only set to re-render after a given period of time has passed, the `value` prop will not be updated on each `apiRef.current.setEditCellValue` call.
When the Data Grid is only set to re-render after a given period of time has passed, the `value` prop will not be updated on each `apiRef.current.setEditCellValue()` call.
To avoid a frozen UI, the edit component can keep the current value in an internal state and sync it once `value` changes.
Modify the edit component to enable this feature:

Expand Down Expand Up @@ -456,8 +456,8 @@ To picture better, imagine an edit component with a combo, created following the
By default, it would require two clicks to change the value of the cell: one click inside the cell to select a new value, and another click outside the cell to save.
This second click can be avoided if the first click also stops the edit mode.
To create an edit component with auto-stop, call `apiRef.current.stopCellEditMode` after setting the new value.
Since `apiRef.current.setEditCellValue` may do additional processing, you must wait for it to resolve before stopping the edit mode.
Also, it is a good practice to check if `apiRef.current.setEditCellValue` has returned `true`.
Since `apiRef.current.setEditCellValue()` may do additional processing, you must wait for it to resolve before stopping the edit mode.
Also, it is a good practice to check if `apiRef.current.setEditCellValue()` has returned `true`.
It will be `false` if `preProcessEditProps` set an error during [validation](#validation).

```tsx
Expand All @@ -479,7 +479,7 @@ The following demo implements an edit component with auto-stop, based on a nativ
{{"demo": "AutoStopEditComponent.js", "bg": "inline", "defaultCodeOpen": false}}

:::warning
Avoid using edit components with auto-stop in columns that use long-running `preProcessEditCellProps` because the UI will freeze while waiting for `apiRef.current.setEditCellValue`.
Avoid using edit components with auto-stop in columns that use long-running `preProcessEditCellProps` because the UI will freeze while waiting for `apiRef.current.setEditCellValue()`.
Instead, use the provided interactions to exit edit mode.
:::

Expand Down
6 changes: 3 additions & 3 deletions docs/data/data-grid/recipes-editing/recipes-editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The code above is already enough to display different options in the **Account**
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.
This function should call `apiRef.current.setEditCellValue()` to reset the value of the other field.

```tsx
const CustomTypeEditComponent = (props: GridEditSingleSelectCellProps) => {
Expand All @@ -77,7 +77,7 @@ The **Account** column is automatically updated with the correct options.
{{"demo": "LinkedFieldsRowEditing.js", "bg": "inline", "defaultCodeOpen": false}}

:::warning
The call to `apiRef.current.setEditCellValue` returns a promise that must be awaited.
The call to `apiRef.current.setEditCellValue()` returns a promise that must be awaited.
For instance, if the `singleSelect` column type is used, not awaiting will cause the other column to be rendered with a `value` that is not in the options.

```ts
Expand All @@ -93,7 +93,7 @@ const handleChange = async () => {
:::

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.
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.

{{"demo": "LinkedFieldsCellEditing.js", "bg": "inline", "defaultCodeOpen": false}}
Expand Down
10 changes: 5 additions & 5 deletions docs/data/data-grid/row-updates/row-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ It replaces the previous values. This approach has some drawbacks:

:::warning
Updating the `rows` prop causes the Data Grid to recompute the row tree, resulting in losing the current tree information like the expanded rows state.
Unless the recomputation is explicitly required, the API method `updateRows` should be used.
Unless the recomputation is explicitly required, the API method `updateRows()` should be used.
:::

## The `updateRows` method
## The `updateRows()` method

If you want to only update part of the rows, you can use the `apiRef.current.updateRows` method.
If you want to only update part of the rows, you can use the `apiRef.current.updateRows()` method.

{{"demo": "UpdateRowsApiRef.js", "bg": "inline"}}

The default behavior of `updateRows` API is to upsert rows.
The default behavior of `updateRows()` API is to upsert rows.
So if a row has an id that is not in the current list of rows then it will be added to the Data Grid.

Alternatively, if you would like to delete a row, you would need to pass an extra `_action` property in the update object as below.
Expand All @@ -33,7 +33,7 @@ apiRef.current.updateRows([{ id: 1, _action: 'delete' }]);
```

:::info
The community version of the Data Grid is limited to a single row update per `apiRef.current.updateRows` call.
The community version of the Data Grid is limited to a single row update per `apiRef.current.updateRows()` call.
Multiple row updates at a time are supported in [Pro](/x/introduction/licensing/#pro-plan) and [Premium](/x/introduction/licensing/#premium-plan) plans.
:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ Most of this breaking change is handled by `preset-safe` codemod but some furthe
+ const focusedField = props.focusedCell;
+ const tabIndex = props.tabbableCell === column.field ? 0 : 1;
```
- Updating the [`rows` prop](/x/react-data-grid/row-updates/#the-rows-prop) or calling `apiRef.current.setRows` will now remove the expansion state of the grid as these methods are meant to replace the rows.
For partial row updates, use the [`apiRef.current.updateRows`](/x/react-data-grid/row-updates/#the-updaterows-method) method instead.
- Updating the [`rows` prop](/x/react-data-grid/row-updates/#the-rows-prop) or calling `apiRef.current.setRows()` will now remove the expansion state of the grid as these methods are meant to replace the rows.
For partial row updates, use the [`apiRef.current.updateRows()`](/x/react-data-grid/row-updates/#the-updaterows-method) method instead.

### Pagination

Expand Down

0 comments on commit a202034

Please sign in to comment.