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] Split Rows doc page #5195

Merged
merged 29 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5c87b59
[docs] Split row doc page
flaviendelangle Jun 14, 2022
44f0e1b
Work
flaviendelangle Jun 14, 2022
481d3d7
Merge branch 'master' into row-doc-split
flaviendelangle Jun 14, 2022
d74944c
Merge branch 'master' into row-doc-split
flaviendelangle Jun 16, 2022
8cf7e83
Work
flaviendelangle Jun 16, 2022
c2486d2
Merge'
flaviendelangle Jun 21, 2022
6bfa81b
Update docs/data/data-grid/row-ordering/row-ordering.md
flaviendelangle Jul 5, 2022
d5e136d
Update docs/data/data-grid/row-ordering/row-ordering.md
flaviendelangle Jul 5, 2022
c0bd17e
Update docs/data/data-grid/row-ordering/row-ordering.md
flaviendelangle Jul 5, 2022
c9be283
Update docs/data/data-grid/row-pinning/row-pinning.md
flaviendelangle Jul 5, 2022
811ca63
Update docs/data/data-grid/row-spanning/row-spanning.md
flaviendelangle Jul 5, 2022
6d282e2
Update docs/data/data-grid/row-dimensions/row-dimensions.md
flaviendelangle Jul 5, 2022
968ff51
Update docs/data/data-grid/row-dimensions/row-dimensions.md
flaviendelangle Jul 5, 2022
787b8dc
Update docs/data/data-grid/row-dimensions/row-dimensions.md
flaviendelangle Jul 5, 2022
dc7847f
Prettier
flaviendelangle Jul 5, 2022
06a0b77
Merge
flaviendelangle Jul 18, 2022
cd892cf
Merge branch 'master' into row-doc-split
cherniavskii Jul 28, 2022
1969030
disable ads for pro features docs
cherniavskii Jul 28, 2022
e3c2b09
simplify scopePathnames
cherniavskii Jul 28, 2022
6d4ce13
move master detail up in the navbar
cherniavskii Jul 28, 2022
29d7f9f
rename row-dimensions page
cherniavskii Jul 28, 2022
783fbd2
remove rows page
cherniavskii Jul 28, 2022
db4f80f
add WIP sections for row grouping and tree data
cherniavskii Jul 28, 2022
f29a70b
empty
cherniavskii Jul 28, 2022
3f1a180
add redirect for /rows/ page
cherniavskii Jul 28, 2022
143a6c9
add missing header
cherniavskii Jul 28, 2022
0f24bb7
update links in the changelog
cherniavskii Jul 28, 2022
f77f4d1
remove unused url properties
cherniavskii Jul 28, 2022
ca150d4
update links to old /rows/ page
cherniavskii Jul 28, 2022
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
54 changes: 54 additions & 0 deletions docs/data/data-grid/row-definition/row-definition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: Data Grid - Row definition
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels vague—it isn't clear what to me what it means to "define" a row. It seems like the page is all about defining row identifiers, so I would go with that.

Suggested change
title: Data Grid - Row definition
title: Data Grid - Defining row identifiers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from row identifiers, this page also mentions rows prop structure and has a warning about keeping the same reference.
Also, "Row definition" is consistent with "Column definition" page https://mui.com/x/react-data-grid/column-definition/

Copy link
Member

@cherniavskii cherniavskii Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Adding missing "Feeding data" section title to make it more clear https://deploy-preview-5195--material-ui-x.netlify.app/x/react-data-grid/row-definition/)

---

# Data grid - Row definition

<p class="description">Define your rows.</p>

The rows can be defined with the `rows` prop, which expects an array of objects.

:::warning
The `rows` prop should keep the same reference between two renders except when you want to apply new rows.
Otherwise, the grid will re-apply heavy work like sorting and filtering.
:::

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

## Row identifier

Each row must have a unique identifier.

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.

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
<DataGrid getRowId={(row) => row.internalId} />
```

{{"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.
:::

## Styling rows

You can check the [styling rows](/x/react-data-grid/style/#styling-rows) section for more information.

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
123 changes: 123 additions & 0 deletions docs/data/data-grid/row-dimensions/row-dimensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Data Grid - Row dimensions
---

# Data grid - Row dimensions
cherniavskii marked this conversation as resolved.
Show resolved Hide resolved

<p class="description">Customize the dimensions of your rows.</p>

## Static row height

By default, the rows have a height of 52 pixels.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
This matches the normal height in the [Material Design guidelines](https://material.io/components/data-tables).

If you want to create a more / less compact grid and not only set the row height, take a look at our [Density documentation](/x/react-data-grid/accessibility/#density-selector)
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

To change the row height for the whole grid, set the `rowHeight` prop:
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

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

## Variable row height

If you need some rows to have different row heights this can be achieved using the `getRowHeight` prop. This function is called for each visible row and if the return value is a `number` then that `number` will be set as that row's `rowHeight`. If the return value is `null` or `undefined` then the `rowHeight` prop will take effect for the given row.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

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

:::warning
Changing the `DataGrid` density does not affect the rows with variable row height.
You can access the density factor from the params provided to the `getRowHeight` prop
:::

:::warning
Always memoize the function provided to `getRowHeight`.
The grid bases on the referential value of these props to cache their values and optimize the rendering.
:::

```tsx
const getRowHeight = React.useCallback(() => { ... }, []);

<DataGridPro getRowHeight={getRowHeight} />
```

## Dynamic row height

Instead of a fixed row height, you can let the grid calculate the height of each row based on its content.
To do so, return `"auto"` on the function passed to the `getRowHeight` prop.

```tsx
<DataGrid getRowHeight={() => 'auto'} />
```

The following demo shows this feature in action:

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

The dynamic row height implementaion is based on a lazy approach, which means that the rows are measured as they are rendered.
Because of this, you may see the size of the scrollbar thumb changing during scroll.
This side effect happens because a row height estimation is used while a row is not rendered, then this value is replaced once the true measurement is obtained.
You can configure the estimated value used by passing a function to the `getEstimatedRowHeight` prop.
If not provided, the default row height of `52px` is used as estimation.
It's recommended to pass this prop if the content deviates too much from the default value.
Note that, due to the implementation adopted, the virtualization of the columns is also disabled to force all columns to be rendered at the same time.

```tsx
<DataGrid getRowHeight={() => 'auto'} getEstimatedRowHeight={() => 200} />
```

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

:::warning
When the height of a row is set to `"auto"`, the final height will follow exactly the content size and ignore the density.
Add padding to the cells to increase the space between the content and the cell borders.

```tsx
<DataGrid
sx={{
'&.MuiDataGrid-root--densityCompact .MuiDataGrid-cell': { py: '8px' },
'&.MuiDataGrid-root--densityStandard .MuiDataGrid-cell': { py: '15px' },
'&.MuiDataGrid-root--densityComfortable .MuiDataGrid-cell': { py: '22px' },
}}
/>
```

:::

flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
## Row spacing

You can use the `getRowSpacing` prop to increase the spacing between rows.
This prop is called with a [`GridRowSpacingParams`](/x/api/data-grid/grid-row-spacing-params/) object.

```tsx
const getRowSpacing = React.useCallback((params: GridRowSpacingParams) => {
return {
top: params.isFirstVisible ? 0 : 5,
bottom: params.isLastVisible ? 0 : 5,
};
}, []);
```

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

By default, setting `getRowSpacing` will change the `marginXXX` CSS properties of each row.
To add a border instead, set `rowSpacingType` to `"border"` and customize the color and style.

```tsx
<DataGrid
getRowSpacing={...}
rowSpacingType="border"
sx={{ '& .MuiDataGrid-row': { borderTopColor: 'yellow', borderTopStyle: 'solid' } }}
/>
```

:::info
⚠ Adding a bottom margin or border to rows that also have a [detail panel](/x/react-data-grid/master-detail/) is not recommended because the detail panel relies on the bottom margin to work.

As an alternative, you can use the top spacing to define the space between rows.
It's easier to always increase the next row spacing no matter if the detail panel is expanded or not, but you can use `gridDetailPanelExpandedRowIdsSelector` to apply a spacing depending on the open state.
:::

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
86 changes: 86 additions & 0 deletions docs/data/data-grid/row-ordering/row-ordering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: Data Grid - Row ordering
---

# Data grid - Row ordering [<span class="plan-pro"></span>](https://mui.com/store/items/mui-x-pro/)

<p class="description">Drag and drop your rows to reorder them.</p>

Row reordering allows to rearrange rows by dragging the special reordering cell.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

By default, row reordering is disabled.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a paragraph describing the default behavior with a link to the Sorting page to let people know how those two features interplay.

I think this information is worth displaying up-front instead of in a warning at the end of the page

To enable it, you need to add the `rowReordering` prop.

```tsx
<DataGridPro rowReordering />
```

{{"demo": "RowOrderingGrid.js", "disableAd": true, "bg": "inline"}}

To capture changes in the order of the dragged row, you can pass a callback to the `onRowOrderChange` prop. This callback is called with a `GridRowOrderChangeParams` object.

In addition, you can import the following events to customize the row reordering experience:

- `rowDragStart`: emitted when dragging of a row starts.
- `rowDragOver`: emitted when dragging a row over another row.
- `rowDragEnd`: emitted when dragging of a row stops.

## Customizing the reorder value

By default, when you start dragging a row, the `id` is displayed in the draggable box.
To change this, you can give a value to the `__reorder__` field for each row.

```tsx
const columns: GridColumns = [{ field: 'brand' }];

const rows: GridRowsProp = [
{ id: 0, brand: 'Nike', __reorder__: 'Nike' },
{ id: 1, brand: 'Adidas', __reorder__: 'Adidas' },
{ id: 2, brand: 'Puma', __reorder__: 'Puma' },
];

<DataGridPro rows={rows} columns={columns} rowReordering />;
```

## Customizing the row reordering icon

To change the icon used for the row reordering, you can provide a different component for the [icon slot](/x/react-data-grid/components/#icons) as follow:

```tsx
<DataGridPro
components={{
RowReorderIcon: CustomMoveIcon,
}}
/>
```

Another way to customize is to add a column with `field: __reorder__` to your set of columns.
That way, you can overwrite any of the properties from the `GRID_REORDER_COL_DEF` column.
The grid will detect that there is already a reorder column defined and it will not add another one in the default position.
By only setting the `field`, is up to you to configure the remaining options (e.g. disable the column menu, filtering, sorting).
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
To already start with a few suggested options configured, spread `GRID_REORDER_COL_DEF` when defining the column.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

```tsx
<DataGridPro
columns={[
{
...GRID_REORDER_COL_DEF, // Already contains the right field
width: 40,
},
]}
/>
```

This approach can also be used to change the location of the toggle column.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanailH What do you think about copying the structure of this example ?

To display both changes instead of adding an explanation after.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I was thinking in terms that this is something that a user can do so I wasn't sure what would be the benefit of showcasing this, but we can add a demo with the dragged column be the last one. The problem with this is that if you have a horizontal scroll then the dragged column will be out of view.


:::warning
For now, row reordering is disabled if sorting is applied to the grid.

In addition, if row grouping or tree data is being used, the row reordering is also disabled.
cherniavskii marked this conversation as resolved.
Show resolved Hide resolved
:::

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
21 changes: 21 additions & 0 deletions docs/data/data-grid/row-pinning/row-pinning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Data Grid - Row pinning
---

# Data grid - Row pinning [<span class="plan-pro"></span>](https://mui.com/store/items/mui-x-pro/)

<p class="description">Pin rows to keep them visible at all time.</p>
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

:::warning
This feature isn't implemented yet. It's coming.

👍 Upvote [issue #1251](https://github.com/mui/mui-x/issues/1251) if you want to see it land faster.
:::

Pinned (or frozen, locked, or sticky) rows are rows that are visible at all times while the user scrolls the grid vertically.

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
24 changes: 24 additions & 0 deletions docs/data/data-grid/row-spanning/row-spanning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Data Grid - Row spanning
---

# Data grid - Row spanning

<p class="description">Span cells across several columns.</p>

:::warning
This feature isn't implemented yet. It's coming.

👍 Upvote [issue #207](https://github.com/mui/mui-x/issues/207) if you want to see it land faster.
:::

Each cell takes up the width of one row.
Row spanning allows to change this default behavior.
It allows cells to span multiple rows.
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
This is very close to the "row spanning" in an HTML `<table>`.

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
56 changes: 56 additions & 0 deletions docs/data/data-grid/row-updates/row-updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Data Grid - Row updates
---

# Data grid - Row updates
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page will require a lot more content in v6 with #4927 and with all the lazy-loading related topics that @DanailH is handling.

It could even require a dedicated page folder at some point with a page for each approach.
But for now, we can improve this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to merge this page with "row definition", to keep consistency with https://mui.com/x/react-data-grid/column-definition/#providing-content? In essence, we're talking here about different approachs to feed the grid with rows. One of the approachs also allows to update rows (updateRows), but it could also be understood as replacing one row with another (updated) row, so "providing rows via API".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joserodolfofreitas @samuelsycamore I'm interested in your opinion here

I agree that this section could be on the same page as the row update sections

image

But having the "Row identifier" section in the same page as well will start to make the page very long.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to split that page into 2, one for Row updates and one for Row loading? The Row loading one will have the infinite + lazy loading and anything else related to loading rows on the fly.

Copy link
Member

@joserodolfofreitas joserodolfofreitas Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it makes sense to move the lazy loading to its own page.
We could probably use one more depth level on the side bar to hold everything about "feeding data", but I agree it makes sense to separate Row updates from Row Loading (and merge Row definitions with Row updates).

But maybe we could rename these menus?

What about

  • Data binding
  • Lazy loading

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can work but calling the page that is about loading rows "Lazy loading" won't be ideal as my idea was to have lazy and infinite loading there.

Copy link
Member

@joserodolfofreitas joserodolfofreitas Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then:

  • Data binding
  • Lazy and infinite loading

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joserodolfofreitas I would add items to the left sidebar. Keeping "lazy loading" inside https://deploy-preview-5195--material-ui-x.netlify.app/x/react-data-grid/row-updates/ will make the page very long. Note that we need to consider that "Row updates" and "Row definition" will be merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanailH @m4theushw @joserodolfofreitas
Did we reach an agreement on this topic? Or should I create a separate issue for discussion to unlock this PR?


<p class="description">Always keep your rows up to date.</p>

## The `rows` prop

The simplest way to update the rows is to provide the new rows using the `rows` prop.
It replaces the previous values. This approach has some drawbacks:

- You need to provide all the rows.
- You might create a performance bottleneck when preparing the rows array to provide to the grid.

{{"demo": "UpdateRowsProp.js", "bg": "inline", "disableAd": true}}

## The `updateRows` method [<span class="plan-pro"></span>](https://mui.com/store/items/mui-x-pro/)

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

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

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

```ts
apiRef.current.updateRows([{ id: 1, _action: 'delete' }]);
```

## Infinite loading [<span class="plan-pro"></span>](https://mui.com/store/items/mui-x-pro/)

The grid provides a `onRowsScrollEnd` prop that can be used to load additional rows when the scroll reaches the bottom of the viewport area.

In addition, the area in which `onRowsScrollEnd` is called can be changed using `scrollEndThreshold`.

{{"demo": "InfiniteLoadingGrid.js", "bg": "inline", "disableAd": true}}

## High frequency [<span class="plan-pro"></span>](https://mui.com/store/items/mui-x-pro/)

Whenever the rows are updated, the grid has to apply the sorting and filters. This can be a problem if you have high frequency updates. To maintain good performances, the grid allows to batch the updates and only apply them after a period of time. The `throttleRowsMs` prop can be used to define the frequency (in milliseconds) at which rows updates are applied.

When receiving updates more frequently than this threshold, the grid will wait before updating the rows.

The following demo updates the rows every 10ms, but they are only applied every 2 seconds.

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

## API

- [DataGrid](/x/api/data-grid/data-grid/)
- [DataGridPro](/x/api/data-grid/data-grid-pro/)
- [DataGridPremium](/x/api/data-grid/data-grid-premium/)
Loading