-
-
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
[DataGrid] Fix filtering with boolean
column type
#15252
Conversation
Deploy preview: https://deploy-preview-15252--material-ui-x.netlify.app/ |
@@ -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 }); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputBoolean.tsx
Outdated
Show resolved
Hide resolved
boolean
column type
Co-authored-by: Armin Mehinovic <armin@mui.com>
Closes #15225
Related to #14327
Before : https://mui.com/x/react-data-grid/filtering/
After : https://deploy-preview-15252--material-ui-x.netlify.app/x/react-data-grid/filtering/