-
-
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] Add quick filtering engine #4317
Conversation
These are the results for the performance tests:
|
packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Outdated
Show resolved
Hide resolved
colDef: GridStateColDef, | ||
apiRef: React.MutableRefObject<GridApiCommunity>, |
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.
Is there a use case where colDef
and apiRef
need to be accessed?
colDef
could be redundant since the function is defined inside the column definition.
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.
For most of the cases it's uselesse. But I had to add those arguments for the single-select column.
From a word in the quick search, I search in valueOptions
the values that have a label corresponding to the word
So I need colDef
to access the valueOptions
. and I need the api
to apply the valueParser
as follow
valueFormatter({ value: option, field, api })
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.
The code is taken form how the GridFilterInputSingleSelect
renders options
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.
In the case maybe deprecate the apiRef
(or api
) since we are going to remove it from GridValueFormatterParams
in v6
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.
The code is taken form how the GridFilterInputSingleSelect renders options
This makes me think that maybe singleSelect
should have a default value formatter in v6. This would avoid having to duplicate code.
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.
@m4theushw I added this to #3287
packages/grid/x-data-grid/src/tests/quickFiltering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Outdated
Show resolved
Hide resolved
e5cadb6
to
48e1272
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
I left some minor visual suggestions. Otherwise, it looks good to me to be released. Good job! How about enabling it in the demo in https://mui.com/x/react-data-grid/demo/?
@@ -27,6 +27,7 @@ const GridToolbarContainerRoot = styled('div', { | |||
})(({ theme }) => ({ | |||
display: 'flex', | |||
alignItems: 'center', | |||
flexWrap: 'wrap', | |||
padding: theme.spacing(0.5, 0.5, 0), |
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.
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.
If I do that, it will also modify the Toolbar even when there is no quick filter
What about adding paddingBottom:theme.spacing(0.5)
to the quick filter component?
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.
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Outdated
Show resolved
Hide resolved
The quick filter seems to work well with demo data. It will be even more interesting when we will get real data 👍 |
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import TextField, { TextFieldProps } from '@mui/material/TextField'; | ||
import SearchIcon from '@mui/icons-material/Search'; |
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.
Our app started failing to compile this morning because it couldn't resolve @mui/icons-material
, seems like it is not added in the dependencies of this module. We had to separately install @mui/icons-material
to get our app working again. We are not using Material Icons in our project at all either, is this an absolute necessity to fetch and use the SearchIcon from Material Icons in this package?
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.
This has been reported in #4906
The fix will be available in next release
Co-authored-by: José Rodolfo Freitas <joserodolfo.freitas@gmail.com>
Fix #2842
The quick filter model I took is the following:
It uses a list of values to filter and it can returns
It's applied after the basic filtering because it makes more comparisons than the basic one.
For now, they both work together (filtered rows must pass both the quick and the basic filtering) This decision is to avoid strange behaviors such as: "When a user set a quick filter value, it reset the filter panel" or "When the quick filter is activated, the filter panel does not have effect"
For now, I added properties in the
filterModel
. I'm not sure if it is the correct way to do that or if filtering should add another modelquickFilterModel
To support row grouping, the signature of the internal method
shouldApplyFilter
is modified. instead of taking a filter item as an input, it takes the columnFieldDemo: https://deploy-preview-4317--material-ui-x.netlify.app/x/react-data-grid/filtering/#quick-filter
TODO
singleSelect
columnsdate
columnsChangelog
You can now add a quick filtering search bar to your grid. To so, either pass
showQuickFilter
prop to the<GridToolbar />
or use the<GridToolbarQuickFilter />
component in your custom toolbar.More information about how to customize the filtering logic in the documentation