feat(react-table): add autoFitColumnsStrategy so DataGrid can auto-fit and resize columns together#36380
Open
AKnassa wants to merge 1 commit into
Conversation
DataGrid columns lose their equal spacing the moment resizableColumns is enabled: auto-fit grows each column to its ideal width and dumps all leftover space on the last column, which also renders without a resize handle - so there is no workaround (microsoft#35923). Add an opt-in resizableColumnsOptions.autoFitColumnsStrategy. 'even' shares the leftover space equally between the columns, matching the flex layout used when resizing is off, while columns the user resizes keep the width they chose. The default 'last-column' behavior is unchanged - no existing test or snapshot was re-baselined. Claude-Session: https://claude.ai/code/session_01MK1FaKzi8LZDrcbrRPESG3
Author
|
@microsoft-github-policy-service agree |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previous Behavior
DataGrid columns are only evenly spaced when column resizing is turned off. As soon as
resizableColumnsis enabled, auto-fit grows each column to its ideal width and gives all of the leftover container space to the last column — four default columns in a 1000px container render as 150 / 150 / 150 / 486 instead of 250 / 250 / 250 / 250. The last column is also rendered without a resize handle, so the one column that ballooned is the one column the user cannot drag back. There is no workaround.New Behavior
A new opt-in option shares the leftover space equally instead:
'even': every column gets its ideal width plus an equal share of the remaining space — the same equally-spaced layout the grid has when resizing is off, while every column (including the last) stays resizable.'last-column'(default): behavior is completely unchanged — no existing test, snapshot, or story was re-baselined, and the default code path was verified byte-identical against the previous implementation across mixed drag/squash sequences.The new
Resizable Columns - Even container auto-fitstory demonstrates the behavior using default columns (nocolumnSizingOptions), which is exactly the reporter's scenario.A decision for maintainers: the issue is really about the default — reporters expect auto-fit + resize to keep equal spacing out of the box. This PR ships the fix as opt-in to stay strictly non-breaking, but we believe
'even'is a strong candidate to become the default in a future major/behavioral release. Happy to follow up either way.Noted while working here, intentionally left out of scope:
columnDefinitionsToStateresets the first over-ideal column where it means the previously-stretched last one (columnResizeUtils.ts, currently masked by an invariant), andTableColumnSizingOptionsdeclares a per-columnautoFitColumnsthat no code reads. Can file separate issues for both.Related Issue(s)
yarn changechange file included (minor)