Skip to content

feat(react-table): add autoFitColumnsStrategy so DataGrid can auto-fit and resize columns together#36380

Open
AKnassa wants to merge 1 commit into
microsoft:masterfrom
AKnassa:fix/35923-datagrid-autofit-with-resizable-columns
Open

feat(react-table): add autoFitColumnsStrategy so DataGrid can auto-fit and resize columns together#36380
AKnassa wants to merge 1 commit into
microsoft:masterfrom
AKnassa:fix/35923-datagrid-autofit-with-resizable-columns

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 10, 2026

Copy link
Copy Markdown

Previous Behavior

DataGrid columns are only evenly spaced when column resizing is turned off. As soon as resizableColumns is 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:

<DataGrid
  resizableColumns
  resizableColumnsOptions={{ autoFitColumnsStrategy: 'even' }}
/>
  • '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.
  • A column the user resizes keeps exactly the width they chose; the other columns share the rest. When the container is too small, unresized columns shrink toward their minimum first, and resized columns only give up what the others cannot absorb.
  • Once every column has been deliberately sized, the columns simply share the container again so no dead space appears after the last column.
  • '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-fit story demonstrates the behavior using default columns (no columnSizingOptions), 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: columnDefinitionsToState resets the first over-ideal column where it means the previously-stretched last one (columnResizeUtils.ts, currently masked by an invariant), and TableColumnSizingOptions declares a per-column autoFitColumns that no code reads. Can file separate issues for both.

Related Issue(s)


  • Changes covered by tests (29 new tests: distribution math, min-width water-fill, resized-column pinning, container/column/options updates, keyboard-resize aria, single-column edge, SSR zero-width container)
  • yarn change change file included (minor)
  • API report regenerated (one added line)
  • 521/521 tests, lint, type-check all passing locally

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
@AKnassa

AKnassa commented Jul 10, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@AKnassa AKnassa marked this pull request as ready for review July 10, 2026 04:40
@AKnassa AKnassa requested a review from a team as a code owner July 10, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DataGrid doesn't support default auto-fit and resize simultaneously

1 participant