Skip to content

[docs] Add a recipe for drag and drop row grouping #17638

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

KenanYusuf
Copy link
Member

@KenanYusuf KenanYusuf commented Apr 30, 2025

Adds a recipe for #5235.

drag.and.drop.row.groups.mov

Todo:

  • Add keyboard navigation, e.g. Shift+Right to move a group right
  • Test screen reader

@KenanYusuf KenanYusuf added docs Improvements or additions to the documentation component: data grid This is the name of the generic UI component, not the React module! feature: Row grouping Related to the data grid Row grouping feature labels Apr 30, 2025
Copy link

github-actions bot commented Apr 30, 2025

Thanks for adding a type label to the PR! 👍

Copy link

Please add one type label to categorize the purpose of this PR appropriately:

bug, regression, enhancement, new feature, release or dependencies

@KenanYusuf KenanYusuf added recipe enhancement This is not a bug, nor a new feature labels Apr 30, 2025
@KenanYusuf
Copy link
Member Author

Please add one type label to categorize the purpose of this PR appropriately:

bug, regression, enhancement, new feature, release or dependencies

Not sure a recipe fits into any of these categories 🤷

@mui-bot
Copy link

mui-bot commented Apr 30, 2025

@KenanYusuf KenanYusuf requested a review from a team April 30, 2025 14:16
@KenanYusuf KenanYusuf marked this pull request as draft April 30, 2025 14:22
Copy link
Member

@cherniavskii cherniavskii left a comment

Choose a reason for hiding this comment

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

Looks very nice 👍🏻

};

return (
<Chip
Copy link
Member

Choose a reason for hiding this comment

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

Should we disable these chips when pivot mode is active? They won't work anyway.

event.preventDefault();

const draggedField = draggedChip || draggedColumn;
if (draggedField && !rowGroupingModel.includes(draggedField)) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be great not to allow dropping non-groupable columns into the toolbar.
And disable chips for non-groupable columns that have been included in the grouping model programatically.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be great not to allow dropping non-groupable columns into the toolbar.

Makes sense 👍

And disable chips for non-groupable columns that have been included in the grouping model programatically.

Is there a use case for this? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Yes, something like this: https://stackblitz.com/edit/1yktkhhd?file=src%2FDemo.tsx
In this demo, the rows are grouped by company, and you cannot ungroup them. You can add more grouping criteria, though.

@@ -18,6 +18,14 @@ Use `GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD` to pin a grouped column. In the de

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

## Creating and reordering groups with drag and drop
Copy link
Member

Choose a reason for hiding this comment

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

Could you also link to this recipe from the toolbar doc page?


return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPremium
Copy link
Member Author

Choose a reason for hiding this comment

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

It would be a much better UX if you could use it with useKeepGroupedColumnsHidden so that when a column gets added to the toolbar, it gets removed from the list of columns and you don't end up with duplicates.

The issue is when a column header gets added to the toolbar on drag over, it is no longer in the DOM, and so the onDragEnd event does not fire. In the demo below you can see how the dragged column state does not get reset.

Screen.Recording.2025-05-02.at.16.40.58.mov

Copy link
Member

Choose a reason for hiding this comment

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

The issue is when a column header gets added to the toolbar on drag over, it is no longer in the DOM, and so the onDragEnd event does not fire.

Is this because we add grouping criteria on dragOver?
I was actually wondering if adding grouping criteria on dragEnd would be a better UX 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation enhancement This is not a bug, nor a new feature feature: Row grouping Related to the data grid Row grouping feature recipe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants