Skip to content

[DataGridPremium] Make row grouping work with negative filtering #16004

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

k-rajat19
Copy link
Contributor

@k-rajat19 k-rajat19 commented Dec 26, 2024

@mui-bot
Copy link

mui-bot commented Dec 26, 2024

Deploy preview: https://deploy-preview-16004--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against bd65b65

@k-rajat19 k-rajat19 marked this pull request as ready for review December 29, 2024 18:00
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Dec 30, 2024
@k-rajat19
Copy link
Contributor Author

Hi @michelengelen, would you like to review this?

Copy link
Member

@michelengelen michelengelen left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @k-rajat19 ... I'll add some reviewers to this! 👍🏼

@cherniavskii cherniavskii added feature: Filtering Related to the data grid Filtering feature feature: Row grouping Related to the data grid Row grouping feature needs cherry-pick The PR should be cherry-picked to master after merge v7.x labels Jan 2, 2025
Copy link
Member

@cherniavskii cherniavskii Jan 2, 2025

Choose a reason for hiding this comment

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

Thank you!
This PR however seems to break the group column filtering in this demo: https://deploy-preview-16004--material-ui-x.netlify.app/x/react-data-grid/row-grouping/#single-grouping-column-2

Can you take a look?

Copy link
Member

Choose a reason for hiding this comment

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

This might be a correct behavior though 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, when mainGroupingCriteria is invalid or not defined we check for leafField, and if that is invalid or not defined we use the top-level grouping criteria, with that in mind I've also written getGroupingCriteria method.
In this demo when we select default behaviour, it sets main grouping criteria to undefined and since there is no leafField it considers top level grouping criteria which is company, so this looks correct behaviour to me.

const filteredRowsLookup: Record<GridRowId, boolean> = {};
const filteredChildrenCountLookup: Record<GridRowId, number> = {};
const filteredDescendantCountLookup: Record<GridRowId, number> = {};
const filterCache = {};

const getGroupingCriteria = () => {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we can call this function only once and use the result, instead of calling it in shouldFilterGroup function for every node. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Also, what's the intetion of this function? I see that it returns null if the grouping column has leafField, can you explain what's the purpose of that?

Copy link
Contributor Author

@k-rajat19 k-rajat19 Jan 5, 2025

Choose a reason for hiding this comment

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

shouldFilterGroup method predicts where filtering can be applied based on the values infilterModel and grouping criteria from getGroupingCriteria method
we don't want to filter the group ( i.e, it returns false) when any of the following conditions are true :

1- there is a valid leafField
2- there are quickFilterValues in filterModel
3- when filtering is applied on the column field which is ungrouped.
4- when rowGroupingColumnMode is multiple and when filtering can be applied on multiple grouping columns,
it returns false when groupingField property in group node from rowTree doesn't match the last field in
groupFilterItems.

5- when there is leaf or footer node in rowTree.

I hope I've not missed any edge case to consider in shouldFilterGroup, also may be we can make things simple here but at the moment I'm not sure how.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like we can call this function only once and use the result, instead of calling it in shouldFilterGroup function for every node. WDYT?

yes, we can improve here

Copy link
Member

Choose a reason for hiding this comment

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

This might be a correct behavior though 🤔

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 10, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link

This pull request has been inactive for 30 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 15 days.

@github-actions github-actions bot added the stale This PR has been inactive for more than 30 days. It will get closed after 90 days of inactivity. label Mar 25, 2025
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! feature: Filtering Related to the data grid Filtering feature feature: Row grouping Related to the data grid Row grouping feature needs cherry-pick The PR should be cherry-picked to master after merge PR: out-of-date The pull request has merge conflicts and can't be merged stale This PR has been inactive for more than 30 days. It will get closed after 90 days of inactivity. v7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Row grouping negative filtering does not work
5 participants