-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Add a recipe limiting to one expanded detail panel at a time #9488
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
docs/data/data-grid/row-recipes/DetailPanelOneExpandedRow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { | ||
randomCreatedDate, | ||
randomCurrency, | ||
randomEmail, | ||
randomPrice, | ||
} from '@mui/x-data-grid-generator'; | ||
|
||
const getDetailPanelContent = ({ row }) => ( | ||
<Box sx={{ p: 2 }}>{`Order #${row.id}`}</Box> | ||
); | ||
const getDetailPanelHeight = () => 50; | ||
|
||
export default function DetailPanelOneExpandedRow() { | ||
const [detailPanelExpandedRowIds, setDetailPanelExpandedRowIds] = React.useState( | ||
[], | ||
); | ||
|
||
const handleDetailPanelExpandedRowIdsChange = React.useCallback((newIds) => { | ||
setDetailPanelExpandedRowIds( | ||
newIds.length > 1 ? [newIds[newIds.length - 1]] : newIds, | ||
); | ||
}, []); | ||
|
||
return ( | ||
<Box sx={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
rows={rows} | ||
columns={columns} | ||
getDetailPanelContent={getDetailPanelContent} | ||
getDetailPanelHeight={getDetailPanelHeight} | ||
detailPanelExpandedRowIds={detailPanelExpandedRowIds} | ||
onDetailPanelExpandedRowIdsChange={handleDetailPanelExpandedRowIdsChange} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
const columns = [ | ||
{ field: 'id', headerName: 'Order ID' }, | ||
{ field: 'customer', headerName: 'Customer', width: 200 }, | ||
{ field: 'date', type: 'date', headerName: 'Placed at' }, | ||
{ field: 'currency', headerName: 'Currency' }, | ||
{ field: 'total', type: 'number', headerName: 'Total' }, | ||
]; | ||
|
||
const rows = [ | ||
{ | ||
id: 1, | ||
customer: 'Matheus', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 2, | ||
customer: 'Olivier', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 3, | ||
customer: 'Flavien', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 4, | ||
customer: 'Danail', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 5, | ||
customer: 'Alexandre', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
]; |
99 changes: 99 additions & 0 deletions
99
docs/data/data-grid/row-recipes/DetailPanelOneExpandedRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { | ||
DataGridPro, | ||
DataGridProProps, | ||
GridRowsProp, | ||
GridRowId, | ||
GridColDef, | ||
} from '@mui/x-data-grid-pro'; | ||
import { | ||
randomCreatedDate, | ||
randomCurrency, | ||
randomEmail, | ||
randomPrice, | ||
} from '@mui/x-data-grid-generator'; | ||
|
||
const getDetailPanelContent: DataGridProProps['getDetailPanelContent'] = ({ | ||
row, | ||
}) => <Box sx={{ p: 2 }}>{`Order #${row.id}`}</Box>; | ||
const getDetailPanelHeight: DataGridProProps['getDetailPanelHeight'] = () => 50; | ||
|
||
export default function DetailPanelOneExpandedRow() { | ||
const [detailPanelExpandedRowIds, setDetailPanelExpandedRowIds] = React.useState< | ||
GridRowId[] | ||
>([]); | ||
|
||
const handleDetailPanelExpandedRowIdsChange = React.useCallback( | ||
(newIds: GridRowId[]) => { | ||
setDetailPanelExpandedRowIds( | ||
newIds.length > 1 ? [newIds[newIds.length - 1]] : newIds, | ||
); | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<Box sx={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
rows={rows} | ||
columns={columns} | ||
getDetailPanelContent={getDetailPanelContent} | ||
getDetailPanelHeight={getDetailPanelHeight} | ||
detailPanelExpandedRowIds={detailPanelExpandedRowIds} | ||
onDetailPanelExpandedRowIdsChange={handleDetailPanelExpandedRowIdsChange} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
const columns: GridColDef[] = [ | ||
{ field: 'id', headerName: 'Order ID' }, | ||
{ field: 'customer', headerName: 'Customer', width: 200 }, | ||
{ field: 'date', type: 'date', headerName: 'Placed at' }, | ||
{ field: 'currency', headerName: 'Currency' }, | ||
{ field: 'total', type: 'number', headerName: 'Total' }, | ||
]; | ||
|
||
const rows: GridRowsProp = [ | ||
{ | ||
id: 1, | ||
customer: 'Matheus', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 2, | ||
customer: 'Olivier', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 3, | ||
customer: 'Flavien', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 4, | ||
customer: 'Danail', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
{ | ||
id: 5, | ||
customer: 'Alexandre', | ||
email: randomEmail(), | ||
date: randomCreatedDate(), | ||
currency: randomCurrency(), | ||
total: randomPrice(1, 1000), | ||
}, | ||
]; |
8 changes: 8 additions & 0 deletions
8
docs/data/data-grid/row-recipes/DetailPanelOneExpandedRow.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<DataGridPro | ||
rows={rows} | ||
columns={columns} | ||
getDetailPanelContent={getDetailPanelContent} | ||
getDetailPanelHeight={getDetailPanelHeight} | ||
detailPanelExpandedRowIds={detailPanelExpandedRowIds} | ||
onDetailPanelExpandedRowIdsChange={handleDetailPanelExpandedRowIdsChange} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Data Grid - Row customization recipes | ||
--- | ||
|
||
# Data Grid - Row customization recipes | ||
|
||
<p class="description">Advanced row customization recipes.</p> | ||
|
||
## One expanded detail panel at a time | ||
|
||
By default, the [Master detail <span class="plan-pro" />](/x/react-data-grid/master-detail/) feature supports multiple expanded detail panels simultaneously. | ||
|
||
However, you can [control the expanded detail panels](/x/react-data-grid/master-detail/#controlling-expanded-detail-panels) to have only one detail panel expanded at a time. | ||
|
||
{{"demo": "DetailPanelOneExpandedRow.js", "bg": "inline", "defaultCodeOpen": false}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import * as pageProps from 'docsx/data/data-grid/row-recipes/row-recipes.md?@mui/markdown'; | ||
|
||
export default function Page() { | ||
return <MarkdownDocs {...pageProps} />; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Another option was to add this example to the Master detail docs, but I decided to avoid increasing the size of the feature doc page and add it here instead.