-
-
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 sortModel
and filterModel
resetting when columns change
#9239
Conversation
Signed-off-by: Alex Goncharenko <[email protected]>
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9239--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.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.
Thanks!
I also added unit tests for both filtering and sorting 👍
setProps({ | ||
columns: [{ field: 'id' }], | ||
filterModel: { | ||
items: [{ field: 'id', operator: 'equals', value: '1' }], |
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.
As the filterModel
prop is updated, technically it's changed, shouldn't this emit a filterModelChange
here? Or we only emit it once it's internally changed. (Same with sortModel
)
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.
Good question!
In controlled mode, we don't call onChange handler if the new value is the same as the prop:
hasPropChanged: newSubState !== controlState.propModel, |
mui-x/packages/grid/x-data-grid/src/hooks/core/useGridStateInitialization.ts
Lines 97 to 103 in a7b87a4
if (controlState.propOnChange && hasPropChanged) { | |
const details = | |
props.signature === GridSignature.DataGridPro | |
? { api: apiRef.current, reason } | |
: { reason }; | |
controlState.propOnChange(model, details); | |
} |
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.
Just a guess, but could this by we are still experiencing an issue? Refresh once and the default filters/sorts are missing. Refresh again and they are back.
sortModel
and filterModel
resetting when columns change
I am sorry to report that this only partially resolved the issue for us.
|
Hey @jonnylink |
@cherniavskii Seeing as this bug fix got us halfway there, I'm fairly confident it's related. |
this is not fixed in version 5? |
@fabianboerner No, the latest stable version is v6 and we're going to release the v7 very soon. |
Fixes #9204
This PR fixes the problem raised in the #9204 issue by implementing the suggestion of @cherniavskii
By replacing useEffect with useLayoutEffect, the
setSortModel
andsetFilterModel
methods are now called before thehandleColumnsChange
runs. This ensures that when both the columns and the respective model(s) change simultaneously, the DataGrid won't fire the onSortModelChange and onFilterModelChange events with erroneously empty models as their parameters.This change fixes the problems I've had in my project, but I haven't tested it beyond that.