-
-
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] Update quick filter input when model is modified #5013
[DataGrid] Update quick filter input when model is modified #5013
Conversation
These are the results for the performance tests:
|
82b81d9
to
08d17eb
Compare
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.
Could you add a test?
|
||
const apiRef = useGridApiContext(); | ||
const rootProps = useGridRootProps(); | ||
const quickFilterValues = gridQuickFilterValuesSelector(apiRef); |
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.
Pass to useGridSelector
?
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Show resolved
Hide resolved
setPrevQuickFilterValues(quickFilterValues); | ||
if (!isDeepEqual(quickFilterParser(searchValue), quickFilterValues)) { | ||
// The input value and the new model are un-sync so we will update the input | ||
setSearchValue(quickFilterFormatter(quickFilterValues ?? [])); |
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.
It's calling this effect twice. You can do two things to improve it:
- use a ref for
prevQuickFilterValues
, since it's not part of the state of the component - instead of
setSearchValue
dosetSearchValue(prevSearchValue => { ... })
to removesearchValue
from the dependencies.
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Show resolved
Hide resolved
packages/grid/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
Show resolved
Hide resolved
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
…erial-ui-x into control-quickfiltering
I added tests, and a sentence in the doc to define this new formatter |
@@ -19,6 +19,15 @@ export const gridFilterModelSelector = createSelector( | |||
(filterState) => filterState.filterModel, | |||
); | |||
|
|||
/** | |||
* Get the current quick filter values. |
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.
* Get the current quick filter values. | |
* Gets the current quick filter values. |
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.
All the other lines are with Get
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.
That's inconsistent because all API methods use the present tense. Anyway, leave as it is and we can fix all later.
@@ -368,13 +368,16 @@ The values used by the quick filter are obtained by splitting with space. | |||
If you want to implement a more advanced logic, the `<GridToolbarQuickFilter/>` component accepts a prop `quickFilterParser`. | |||
This function takes the string from the search text field and returns an array of values. | |||
|
|||
If you control the `quickFilterValues` either by controlling `filterModel` or with the initial state, you should provide a `quickFilterFormatter` which will be used to update the content of the input. |
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 didn't understand this part. There's a default value formatter so the user doesn't need to always pass one.
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 tried to be more explicit
packages/grid/x-data-grid/src/tests/quickFiltering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/quickFiltering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
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.
Looks good!
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Fix #4921
I assume the quick filter value is rarely modified from somewhere else. It can be reset by clicking a button, or when putting back a saved state.
From this, I propose to add a prop to the input named
quickFilterFormatter
. This prop is used only if the quick filter state is updated and does not correspond anymore to the input content. In such a case, we use thisquickFilterFormatter
to update the input content.