-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGridPremium] Automatic parents and children selection (#13757)
Signed-off-by: Bilal Shafi <[email protected]> Co-authored-by: José Rodolfo Freitas <[email protected]> Co-authored-by: Andrew Cherniavskii <[email protected]>
- Loading branch information
1 parent
c39b734
commit 978a438
Showing
22 changed files
with
1,380 additions
and
59 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
docs/data/data-grid/row-grouping/RowGroupingPropagateSelection.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,72 @@ | ||
import * as React from 'react'; | ||
import { | ||
DataGridPremium, | ||
useGridApiRef, | ||
useKeepGroupedColumnsHidden, | ||
} from '@mui/x-data-grid-premium'; | ||
import { useMovieData } from '@mui/x-data-grid-generator'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import Stack from '@mui/material/Stack'; | ||
|
||
export default function RowGroupingPropagateSelection() { | ||
const data = useMovieData(); | ||
const apiRef = useGridApiRef(); | ||
const [rowSelectionPropagation, setRowSelectionPropagation] = React.useState({ | ||
parents: true, | ||
descendants: true, | ||
}); | ||
|
||
const initialState = useKeepGroupedColumnsHidden({ | ||
apiRef, | ||
initialState: { | ||
rowGrouping: { | ||
model: ['company', 'director'], | ||
}, | ||
}, | ||
}); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<Stack direction="row" spacing={2}> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={rowSelectionPropagation.descendants} | ||
onChange={(event) => | ||
setRowSelectionPropagation((prev) => ({ | ||
...prev, | ||
descendants: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select descendants" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={rowSelectionPropagation.parents} | ||
onChange={(event) => | ||
setRowSelectionPropagation((prev) => ({ | ||
...prev, | ||
parents: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select parents" | ||
/> | ||
</Stack> | ||
<div style={{ height: 400 }}> | ||
<DataGridPremium | ||
{...data} | ||
apiRef={apiRef} | ||
initialState={initialState} | ||
checkboxSelection | ||
rowSelectionPropagation={rowSelectionPropagation} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
74 changes: 74 additions & 0 deletions
74
docs/data/data-grid/row-grouping/RowGroupingPropagateSelection.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,74 @@ | ||
import * as React from 'react'; | ||
import { | ||
DataGridPremium, | ||
useGridApiRef, | ||
useKeepGroupedColumnsHidden, | ||
GridRowSelectionPropagation, | ||
} from '@mui/x-data-grid-premium'; | ||
import { useMovieData } from '@mui/x-data-grid-generator'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import Stack from '@mui/material/Stack'; | ||
|
||
export default function RowGroupingPropagateSelection() { | ||
const data = useMovieData(); | ||
const apiRef = useGridApiRef(); | ||
const [rowSelectionPropagation, setRowSelectionPropagation] = | ||
React.useState<GridRowSelectionPropagation>({ | ||
parents: true, | ||
descendants: true, | ||
}); | ||
|
||
const initialState = useKeepGroupedColumnsHidden({ | ||
apiRef, | ||
initialState: { | ||
rowGrouping: { | ||
model: ['company', 'director'], | ||
}, | ||
}, | ||
}); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<Stack direction="row" spacing={2}> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={rowSelectionPropagation.descendants} | ||
onChange={(event) => | ||
setRowSelectionPropagation((prev) => ({ | ||
...prev, | ||
descendants: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select descendants" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={rowSelectionPropagation.parents} | ||
onChange={(event) => | ||
setRowSelectionPropagation((prev) => ({ | ||
...prev, | ||
parents: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select parents" | ||
/> | ||
</Stack> | ||
<div style={{ height: 400 }}> | ||
<DataGridPremium | ||
{...data} | ||
apiRef={apiRef} | ||
initialState={initialState} | ||
checkboxSelection | ||
rowSelectionPropagation={rowSelectionPropagation} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
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
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
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
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
Oops, something went wrong.