Skip to content
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

[DataGrid] Fix filtering with boolean column type #15252

Merged
merged 6 commits into from
Nov 4, 2024

Conversation

k-rajat19
Copy link
Contributor

@k-rajat19 k-rajat19 commented Nov 4, 2024

@mui-bot
Copy link

mui-bot commented Nov 4, 2024

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

Generated by 🚫 dangerJS against f1af66e

@k-rajat19 k-rajat19 marked this pull request as ready for review November 4, 2024 07:14
@@ -54,13 +54,14 @@ function GridFilterInputBoolean(props: GridFilterInputBooleanProps) {
(event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setFilterValueState(value);
applyValue({ ...item, value: Boolean(value) });

applyValue({ ...item, value: value ? String(value).toLowerCase() === 'true' : value });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arminmeh do you think we should also support uppercase values ?

 filterModel: {
              items: [
                {
                  field: 'isAdmin',
                  operator: 'is',
                  value: "TRUE",
                },
              ],
            },

that's why I have used .toLowerCase()

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this. I have expanded this even further

Since the earlier change strives to have boolean values in the filter model, I have refactored things to be boolean first and used a helper to make sure filter still responds correctly if strings (even invalid ones) are passed via setFilterModel API.

I have also expanded tests to cover some of these cases.

Let me know if you see any problems with it.

@mui/xgrid
Can someone else review this, since now I have my code in here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks this looks cleaner and more organized.

@arminmeh arminmeh self-requested a review November 4, 2024 07:45
@arminmeh arminmeh added component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse feature: Filtering Related to the data grid Filtering feature needs cherry-pick The PR should be cherry-picked to master after merge labels Nov 4, 2024
@arminmeh arminmeh requested a review from a team November 4, 2024 11:15
@arminmeh arminmeh changed the title [DataGrid] Fix Filtering with Boolean Column type [DataGrid] Fix filtering with boolean column type Nov 4, 2024
@arminmeh arminmeh merged commit eb2cae5 into mui:master Nov 4, 2024
18 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 4, 2024
Co-authored-by: Armin Mehinovic <armin@mui.com>
@k-rajat19 k-rajat19 deleted the boolean-col branch November 4, 2024 13:19
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 needs cherry-pick The PR should be cherry-picked to master after merge regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Filtering Boolean Columns. Filter Model sends value = true, when false filter is selected.
4 participants