-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 24 commits
5c87b59
44f0e1b
481d3d7
d74944c
8cf7e83
c2486d2
6bfa81b
d5e136d
c0bd17e
c9be283
811ca63
6d282e2
968ff51
787b8dc
dc7847f
06a0b77
cd892cf
1969030
e3c2b09
6d4ce13
29d7f9f
783fbd2
db4f80f
f29a70b
3f1a180
143a6c9
0f24bb7
f77f4d1
ca150d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: 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/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
--- | ||
title: Data Grid - Row height | ||
--- | ||
|
||
# Data grid - Row height | ||
|
||
<p class="description">Customize the height of your rows.</p> | ||
|
||
## Static row height | ||
|
||
By default, the rows have a height of 52 pixels. | ||
This matches the normal height in the [Material Design guidelines](https://material.io/components/data-tables). | ||
|
||
Use the the `rowHeight` prop to change this default value, as shown below: | ||
|
||
{{"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. | ||
|
||
{{"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' }, | ||
}} | ||
/> | ||
``` | ||
|
||
::: | ||
|
||
## Row density | ||
|
||
Give your users the option to change the default row density to match their preferences—compact, standard, or comfortable. | ||
Density is calculated based on the `rowHeight` and/or `headerHeight` props, when present. | ||
See [Density](https://mui.com/x/react-data-grid/accessibility/#density) for details. | ||
|
||
## 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/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
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 lets users rearrange rows by dragging the special reordering cell. | ||
|
||
By default, row reordering is disabled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
If you only set the `field`, then it is up to you to configure the remaining options (e.g. disable the column menu, filtering, sorting). | ||
To start with our suggested configuration, spread `GRID_REORDER_COL_DEF` when defining the column. | ||
|
||
```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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
::: | ||
|
||
## Reordering rows with row grouping 🚧 | ||
|
||
:::warning | ||
This feature isn't implemented yet. It's coming. | ||
|
||
👍 Upvote [issue #4821](https://github.com/mui/mui-x/issues/4821) if you want to see it land faster. | ||
::: | ||
|
||
## Reordering rows with tree data 🚧 | ||
|
||
:::warning | ||
This feature isn't implemented yet. It's coming. | ||
|
||
👍 Upvote [issue #4821](https://github.com/mui/mui-x/issues/4821) if you want to see it land faster. | ||
::: | ||
|
||
## API | ||
|
||
- [DataGrid](/x/api/data-grid/data-grid/) | ||
- [DataGridPro](/x/api/data-grid/data-grid-pro/) | ||
- [DataGridPremium](/x/api/data-grid/data-grid-premium/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
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 times.</p> | ||
|
||
Pinned (or frozen, locked or floating) rows are those visible at all times while the user scrolls the grid vertically. | ||
|
||
:::warning | ||
This feature is experimental, it needs to be explicitly activated using the `rowPinning` experimental feature flag. | ||
|
||
```tsx | ||
<DataGridPro experimentalFeatures={{ rowPinning: true }} {...otherProps} /> | ||
``` | ||
|
||
::: | ||
|
||
You can pin rows at the top or bottom of the grid by passing pinned rows data through the `pinnedRows` prop: | ||
|
||
```tsx | ||
const pinnedRows: GridPinnedRowsProp = { | ||
top: [{ id: 0, brand: 'Nike' }], | ||
bottom: [ | ||
{ id: 1, brand: 'Adidas' }, | ||
{ id: 2, brand: 'Puma' }, | ||
], | ||
}; | ||
|
||
<DataGridPro pinnedRows={pinnedRows} />; | ||
``` | ||
|
||
The data format for pinned rows is the same as for the `rows` prop (see [Feeding data](/x/react-data-grid/rows/#feeding-data)). | ||
|
||
Pinned rows data should also meet [Row identifier](/x/react-data-grid/rows/#row-identifier) requirements. | ||
|
||
{{"demo": "RowPinning.js", "disableAd": true, "bg": "inline"}} | ||
|
||
:::warning | ||
Just like the `rows` prop, `pinnedRows` prop should keep the same reference between two renders. | ||
Otherwise, the grid will re-apply heavy work like sorting and filtering. | ||
::: | ||
|
||
## Controlling pinned rows | ||
|
||
You can control which rows are pinned by changing `pinnedRows`. | ||
|
||
In the demo below we use `actions` column type to add buttons to pin a row either at the top or bottom and change `pinnedRows` prop dynamically. | ||
|
||
{{"demo": "RowPinningWithActions.js", "disableAd": true, "bg": "inline", "defaultCodeOpen": false}} | ||
|
||
## Usage with other features | ||
|
||
Pinned rows are not affected by sorting and filtering. | ||
|
||
Pagination does not impact pinned rows as well - they stay pinned regardless the page number or page size. | ||
|
||
{{"demo": "RowPinningWithPagination.js", "disableAd": true, "bg": "inline", "defaultCodeOpen": false}} | ||
|
||
:::info | ||
Pinned rows do not support the following features: | ||
|
||
- editing ([issue #5591](https://github.com/mui/mui-x/issues/5591)) | ||
- selection | ||
- row grouping | ||
- tree data | ||
- row reordering | ||
- master detail | ||
::: | ||
|
||
## API | ||
|
||
- [DataGrid](/x/api/data-grid/data-grid/) | ||
- [DataGridPro](/x/api/data-grid/data-grid-pro/) | ||
- [DataGridPremium](/x/api/data-grid/data-grid-premium/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
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 lets you change this default behavior, so cells can span multiple rows. | ||
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/) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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/)