-
-
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
[data grid] Group Item With Checkbox Select Children #13277
Comments
@cherniavskii we had a similar issue already, but I cannot find it ... 🤔 |
@cherniavskii nvm ... found it. @KSafadi we currently do not support this behavior OOTB, but we have a working example written up here: #13036 This basically does exactly what you want. Let me know if using this fixes your use case! |
Could you show how to integrate this into the sample that was provided? |
@KSafadi @tsafadi here is the updated example |
@KSafadi did this solution work for you? |
Yes, thank you so much! Sorry for the delay |
@KSafadi: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
@michelengelen The header checkbox is not working as expected like when we click on it it is selecting everything but when selecting it again was not deselecting all. Also when we remove some selections from the rows it should go to indeterminate state but nothing is happening! I tried to debug and but nothing worked! |
The solution that you provided is perfect. However, the select all from the header does not work anymore. Could you show how to fix that? Or is there an option to disable or remove the checkbox from the header? |
🎉 Checkbox Selection Enhancement for MUI DataGridGreat news, @michelengelen @tsafadi! I've addressed the issue you reported with the header checkbox functionality. This solution improves the user experience and brings the checkbox behavior in line with expected standards. 🔧 Key Improvements:
💡 Implementation Highlights:
🚀 Benefits:
#MUI #OpenSource #DataGrid #UserExperience const checkboxColumn = (apiRef: MutableRefObject<GridApiPro>): GridColDef => {
return {
...GRID_CHECKBOX_SELECTION_COL_DEF,
renderHeader: function RenderHeader(params) {
const children = gridFilteredSortedRowIdsSelector(
apiRef.current.state,
apiRef.current.instanceId
).filter((id) => !id.toString().includes("auto-generated"));
const selectionLookup = useGridSelector(
apiRef,
gridRowSelectionStateSelector
);
const indeterminate =
children?.some((child) => selectionLookup.includes(child)) &&
children?.some((child) => !selectionLookup.includes(child));
const checked = children?.every((child) =>
selectionLookup.includes(child)
);
const data: GridColumnHeaderParams & {
indeterminate?: boolean;
checked?: boolean;
disabled?: boolean;
onClick?: (e: MouseEvent) => void;
} = {
...params,
onClick: (e) => {
apiRef.current.selectRows(children, indeterminate || !checked);
e.preventDefault();
},
indeterminate,
checked,
};
return (
<>
<GridHeaderCheckbox {...data} />
</>
);
},
renderCell: function RenderCell(params) {
const { rowNode } = params;
const selectionLookup = useGridSelector(
apiRef,
gridRowSelectionStateSelector
);
if (rowNode.type !== "group") {
return <GridCellCheckboxRenderer {...params} />;
}
const children = apiRef.current.getRowGroupChildren({
groupId: rowNode.id,
applyFiltering: true,
applySorting: true,
});
const indeterminate =
children?.some((child) => selectionLookup.includes(child)) &&
children?.some((child) => !selectionLookup.includes(child));
const checked = children?.every((child) =>
selectionLookup.includes(child)
);
const extraData: GridRenderCellParams & {
indeterminate?: boolean;
checked?: boolean;
disabled?: boolean;
onClick?: (e: MouseEvent) => void;
} = {
...params,
disabled: false,
onClick: (e) => {
if (rowNode.type === "group") {
if (children) {
apiRef.current.selectRows(
[rowNode.id, ...children],
indeterminate || !checked
);
}
e.preventDefault();
}
},
indeterminate,
checked,
};
return <GridCellCheckboxRenderer {...extraData} />;
},
};
}; |
The problem in depth
I have a grouping in my MUI DataGrid and a checkbox selection. When the checkbox of the group headers are clicked, nothing happens. I need all the children to be selected when the group is selected, similar to the header checkbox selection.
I have provided a demo: https://stackblitz.com/edit/react-mqcgmm?file=Demo.tsx
Your environment
`npx @mui/envinfo`
Search keywords: DataGrid Grouping CheckBox Selection
Order ID: 89911
The text was updated successfully, but these errors were encountered: