Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Improve the getRowId doc section #5156

Merged
merged 5 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/data/data-grid/rows/rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ Otherwise, the grid will re-apply heavy work like sorting and filtering.

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

:::warning
Each row object should have a field that uniquely identifies the row.
By default, the grid will use the `id` property of the row. Note that [column definition](/x/react-data-grid/column-definition/) for `id` field is not required.
## Row identifier

Each row must have a unique id.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

When using dataset without a unique `id` property, you can use the `getRowId` prop to specify a custom id for each row.
This id is used internally to identify the row in the various models (for instance the row selection model) and to track the row across updates.
By default, the grid will use the `id` property of the row.

When using a dataset without a unique `id` property, you can use the `getRowId` prop to specify the id of each row.
This can be useful if your id is stored in another property like shown below:
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

```tsx
<DataGrid getRowId={(row) => row.internalId} />
```

{{"demo": "RowsGridWithGetRowId.js", "bg": "inline", "defaultCodeOpen": false}}

flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
:::warning
Just like the `rows` prop, the `getRowId` prop should keep the same reference between two renders.
Otherwise, the grid will re-apply heavy work like sorting and filtering.
:::

## Updating rows

### The `rows` prop
Expand Down