-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Data Grid] Add new includeHeaderFilters flag to include header filters when autosizing columns
#20510
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
Merged
Conversation
This file contains hidden or 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
…o feat/resize-header-filter
|
Deploy preview: https://deploy-preview-20510--material-ui-x.netlify.app/ Updated pages: Bundle size report
|
docs/data/data-grid/column-dimensions/ColumnAutosizingHeaderFilters.js
Outdated
Show resolved
Hide resolved
packages/x-data-grid/src/hooks/features/columnResize/gridColumnResizeApi.ts
Show resolved
Hide resolved
packages/x-data-grid/src/hooks/features/columnResize/useGridColumnResize.tsx
Outdated
Show resolved
Hide resolved
MBilalShafi
reviewed
Dec 17, 2025
MBilalShafi
approved these changes
Dec 18, 2025
cherniavskii
approved these changes
Dec 18, 2025
siriwatknp
added a commit
to siriwatknp/material-ui-x
that referenced
this pull request
Dec 19, 2025
…ters when autosizing columns (mui#20510)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature: Column resize
scope: data grid
Changes related to the data grid.
type: new feature
Expand the scope of the product to solve a new problem.
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.
closes #13802
preview: https://deploy-preview-20510--material-ui-x.netlify.app/x/react-data-grid/column-dimensions/#autosizing-header-filters
🎯 Main Purpose
Adds a new
includeHeaderFiltersoption toautosizeOptionsthat makes the column autosize algorithm consider header filter widths, preventing filter inputs from being squeezed when columns have short content.🔍 Problem & Solution Context
Issue: When using header filters with columns that have short headers and short content, the autosize feature would make columns too narrow, causing the filter input to become unusable.
Example scenario: A column with header "ID" and values like "1", "2", "3" would autosize to a very narrow width, leaving no room for the filter input.
Solution: New
includeHeaderFilters: trueoption tells autosize to also measure the header filter cell width and include it in the column width calculation.🔧 Key Changes
includeHeaderFiltersboolean option inautosizeOptions(defaults tofalse)findGridHeaderFilter()utility to locate header filter elements📁 Important Files
useGridColumnResize.tsx- Core width measurement logic; adds header filter width to the pool of widths considered during autosizingGridRootStyles.ts- Adds CSS overrides for header filter cells during autosize measurement (uses!importantto override flex layout)📋 Usage Example
Or programmatically:
🚀 Impact
false💡 Implementation Notes
Why
flex: noneandwidth: unsetin CSS?Header filter cells normally use
flex: 1and a fixedwidthwhich constrains them to their column width. During autosizing, we need to measure the natural content width (how wide the filter input wants to be), not the constrained width. Settingflex: noneandwidth: unsetallows the element to expand to its intrinsic size soscrollWidthreturns the true content width.Why
window.getComputedStylefor padding instead ofgetBoundingClientRectorclientWidth?getBoundingClientRect().widthreturns the rendered width (constrained by flex/column width), not the content's natural widthclientWidthincludes padding but still reflects the constrained rendered widthscrollWidthgives the full content width including overflow, but excludes paddinggetComputedStyleis used specifically to get the padding values to add toscrollWidth, giving us:scrollWidth + paddingLeft + paddingRight = true natural widthThis matches the existing pattern used for header cells in the same file.
Note
The
!importantin GridRootStyles is scoped to the.MuiDataGrid--autosizingstate and only affects header filter cells during measurement.