-
-
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
[DataGridPro] Fix onColumnWidthChange
being called twice on autosize
#12140
Merged
romgrk
merged 17 commits into
mui:next
from
shaharyar-shamshi:hotfix/fix-columnWidthChange-on-double-click
Feb 27, 2024
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
70d8729
fix onColumnWidthChange called before autosize affects column width
shaharyar-shamshi 6d09b48
fix onColumnWidthChange called before autosize affects column width
shaharyar-shamshi 77c6ee8
native event stored instead of synthtic event
shaharyar-shamshi 5c35631
native event stored instead of synthtic event
shaharyar-shamshi f4c7693
native event stored instead of synthtic event
shaharyar-shamshi 8b96f02
native event stored instead of synthtic event
shaharyar-shamshi e38b370
native event stored instead of synthtic event
shaharyar-shamshi 417c43d
native event stored instead of synthtic event
shaharyar-shamshi cd8cc5b
width of the new column added
shaharyar-shamshi e3b0d63
test case added
shaharyar-shamshi 27f1ad5
test case added
shaharyar-shamshi 69e1a42
test case added
shaharyar-shamshi ce71551
unnecessary comment removed
shaharyar-shamshi d56332d
typo fixed
shaharyar-shamshi 57a4903
resize event fired for multiple column
shaharyar-shamshi ca1e9d5
column width trigger for only changed column
shaharyar-shamshi e80c76a
column width trigger for only changed column
shaharyar-shamshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will trigger for all columns regardless of if they have changed. You have the original columns in
columns
.You can avoid typings like this, the inference knows it's a number:
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.
We are doing something wrong this implementation is correct.
let me Explain in detail
There are two possibility of calling autosizeColumns function
here each of the column is being resized on mounting
In our case to solve this bug we only need to concentrate on case 1 when the autosizeColumns is called on double click.
So on double click event from https://github.com/mui/mui-x/blob/next/packages/x-data-grid-pro/src/hooks/features/columnResize/useGridColumnResize.tsx#L661
we get only one column that needs to be resized and we need not check on all the columns.
Now in case 2 when autOResizeOnMount is called in that case all the columns should be resized and we need to decide whether to publish event or not.
So from both the case we can figure it out that either all of the column will be resized or only 1 will be resized.
if we want to disable the event publish on all column resize (case 2) we just need to add one condition
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 is no need for an
if
guard, just check the array and dispatch one event for each column that actually changed. ComparenewColumn.width !== columns[index].width
in the.forEach
loop to figure out which ones changed.The autosize function is part of the public API and can be called programatically with any number of columns.
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.
Okk then we need to consider this I thought it is not the public 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.
Done