From 41112d95dcd682590d65e9ae127e64e6d818279e Mon Sep 17 00:00:00 2001 From: flavien Date: Thu, 9 Jun 2022 11:10:54 +0200 Subject: [PATCH 1/5] [docs] Improve the getRowId doc section --- docs/data/data-grid/rows/rows.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/data/data-grid/rows/rows.md b/docs/data/data-grid/rows/rows.md index b3dec00597c3..bcb66ea3cb76 100644 --- a/docs/data/data-grid/rows/rows.md +++ b/docs/data/data-grid/rows/rows.md @@ -17,11 +17,15 @@ 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. -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: ```tsx row.internalId} /> @@ -29,6 +33,11 @@ When using dataset without a unique `id` property, you can use the `getRowId` pr {{"demo": "RowsGridWithGetRowId.js", "bg": "inline", "defaultCodeOpen": false}} +:::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 From 5ae1e92f702f4fd75ecdc856a417e8c286d50772 Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Fri, 10 Jun 2022 10:00:06 +0200 Subject: [PATCH 2/5] Update docs/data/data-grid/rows/rows.md Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> --- docs/data/data-grid/rows/rows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/data/data-grid/rows/rows.md b/docs/data/data-grid/rows/rows.md index bcb66ea3cb76..a2adf9ad7350 100644 --- a/docs/data/data-grid/rows/rows.md +++ b/docs/data/data-grid/rows/rows.md @@ -19,7 +19,7 @@ Otherwise, the grid will re-apply heavy work like sorting and filtering. ## Row identifier -Each row must have a unique id. +Each row must have a unique identifier. 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. From 7927aae66d020c2458ed1e3d4fe8d03dca76fc3c Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Fri, 10 Jun 2022 10:00:50 +0200 Subject: [PATCH 3/5] Update docs/data/data-grid/rows/rows.md Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> --- docs/data/data-grid/rows/rows.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/data/data-grid/rows/rows.md b/docs/data/data-grid/rows/rows.md index a2adf9ad7350..0866b232a3cd 100644 --- a/docs/data/data-grid/rows/rows.md +++ b/docs/data/data-grid/rows/rows.md @@ -21,11 +21,13 @@ Otherwise, the grid will re-apply heavy work like sorting and filtering. Each row must have a unique identifier. -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. +This identifier is used internally to identify the row in the various models—for instance, the row selection model—and to track the row across updates. -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: +By default, the data grid looks for a property named `id` in the data set to get that identifier. + +If the row's identifier is not called `id`, then you need to use the `getRowId` prop to tell the grid where it's located. + +The following demo shows how to use `getRowId` to grab the unique identifier from a property named `internalId`: ```tsx row.internalId} /> From 3b71e9c1e2549e75c5105d92421e24482e69fde7 Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Fri, 10 Jun 2022 10:01:10 +0200 Subject: [PATCH 4/5] Update docs/data/data-grid/rows/rows.md Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> --- docs/data/data-grid/rows/rows.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/data/data-grid/rows/rows.md b/docs/data/data-grid/rows/rows.md index 0866b232a3cd..c237eaf86024 100644 --- a/docs/data/data-grid/rows/rows.md +++ b/docs/data/data-grid/rows/rows.md @@ -35,6 +35,11 @@ The following demo shows how to use `getRowId` to grab the unique identifier fro {{"demo": "RowsGridWithGetRowId.js", "bg": "inline", "defaultCodeOpen": false}} +If no such unique identifier exists in the data set, then you must create it by some other means, but this scenario should be avoided because it leads to issues with other features of the grid. + +Note that it is not necessary to create a column to display the unique identifier data. +The data grid pulls this information directly from the data set itself, not from anything that is displayed on the screen. + :::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. From a510f8d52229af7e408a499820725290d8132fa2 Mon Sep 17 00:00:00 2001 From: delangle Date: Fri, 10 Jun 2022 10:34:28 +0200 Subject: [PATCH 5/5] Prettier --- docs/data/data-grid/rows/rows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/data/data-grid/rows/rows.md b/docs/data/data-grid/rows/rows.md index c237eaf86024..81ffd1c067c3 100644 --- a/docs/data/data-grid/rows/rows.md +++ b/docs/data/data-grid/rows/rows.md @@ -37,7 +37,7 @@ The following demo shows how to use `getRowId` to grab the unique identifier fro If no such unique identifier exists in the data set, then you must create it by some other means, but this scenario should be avoided because it leads to issues with other features of the grid. -Note that it is not necessary to create a column to display the unique identifier data. +Note that it is not necessary to create a column to display the unique identifier data. The data grid pulls this information directly from the data set itself, not from anything that is displayed on the screen. :::warning