Skip to content

fix(grid): pin a column with a small minWidth through pinned - #18064

Merged
kdinev merged 10 commits into
masterfrom
ibarakov/fix-18039
Dec 4, 2026
Merged

kdinev merged 10 commits into
masterfrom
ibarakov/fix-18039

Conversation

@onlyexeption

@onlyexeption onlyexeption commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #18039

Description

Setting pinned now pins and unpins a column that has no width and a minWidth below 136px, even when the grid has no space left for that column. Setting pinned on a hidden column that has no width also pins it when it is shown.

Changes in getPossibleColumnWidth() (grid-base.directive.ts):

  • When every visible column has a width or is held at its minWidth or maxWidth, the held columns are sized again with the space the other columns leave, so they follow the grid width.
  • When every visible column has a width, it returns the minimum column width (136px) instead of dividing by 0, so a hidden column without a width gets a pixel width. Multi-row layouts are not changed.

Changes in cacheCalcWidth() (column.component.ts), for a column that has no width and a minWidth below 136px:

  • Before it calculates the possible width, it resets widthConstrained, so the column is always sized with the columns that have no width.
  • defaultWidth is set to the calculated width, so width returns a pixel value such as 50px.

Motivation / Context

After the first sizing pass, a column held at its minWidth or maxWidth is marked widthConstrained, so the next pass no longer counts it with the columns that have no width. When it is the only such column, getPossibleColumnWidth() divides by 0, and width returns -Infinitypx or Infinitypx. The pinned setter calls pin() or unpin() only when parseInt(width) is a number. Otherwise it only changes the flag, so the column stays where it was. A hidden column without a width gets the same non-finite width when every visible column has a width or is held at its minWidth or maxWidth.

The non-finite width also kept a column at its maxWidth after the grid got narrower, so the grid showed a horizontal scrollbar. The column now takes the space that is left, as it does when the grid starts at that width.

The bug has existed since 20.1.0 (#16134). The fixes suggested in the issue break existing sizing behavior, such as #16057.

Needs backports to 22.3.x and 21.2.x.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

Grids (Grid, Tree Grid, Hierarchical Grid): column sizing and pinning

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

New tests (all 8 fail on master):

  • grid.pinning.spec.ts:
    • The issue's setup: pins and unpins the column through the pinned input
    • The issue's setup: unpins the column through the pinned property after pin()
    • Pins a hidden column with a minWidth below 136px through the pinned input when it is shown
    • Pins a hidden column without a width when it is shown, when every visible column has a width
    • The same, when the other column without a width is held at its maxWidth
  • column-resizing.spec.ts:
    • When the grid has no space left, the columns are sized to their minWidth (width is 50px and calcPixelWidth is 50)
    • A column with only maxWidth="300px" is 300px wide in a 1000px grid, and 200px with no horizontal scrollbar after the grid shrinks to 400px
    • A column held at minWidth="300px" grows to 1000px when the grid widens from 400px to 1200px

The last 2 also fail on the previous commit of this PR. They cover the regression found in review.

Regression: all 83 grid spec files (3,676 tests) pass, and npm run lint:lib reports no errors. Also checked in the demo app: the #18039 tab pins and unpins the column, and in a local sample with the two cases from review, the columns follow the grid width.

Test Configuration:

  • Angular version: 22.3.0
  • Browser(s): Chromium (Vitest browser mode)
  • OS: Windows 11

Screenshots / Recordings

N/A

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

@onlyexeption
onlyexeption requested a balanced review from Copilot November 26, 2026 08:17
@onlyexeption onlyexeption added the ❌ status: awaiting-test PRs awaiting manual verification label Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not cover the new non-finite-width fallback for hidden columns; a regression case should verify minimum-width calculation and pinning/unpinning after the column is shown.

1 open issue
What changed in this PR

Fixes #18039 in shared grid column sizing so columns without an explicit width and with minWidth below 136px can be pinned and unpinned when space is exhausted, while preserving the smaller-width behavior introduced for #16057.

Changes:

  • Recalculates eligible column widths, handles non-finite results, and stores the constrained pixel width.
  • Adds regression tests for pinning and minimum-width sizing.
  • Documents the fix in the changelog.
File Description
projects/​igniteui-angular/​grids/​grid/​src/​grid.pinning.spec.ts Tests pinning through the input and unpinning through the property.
projects/​igniteui-angular/​grids/​grid/​src/​column-resizing.spec.ts Verifies minimum widths when grid space is exhausted.
projects/​igniteui-angular/​grids/​core/​src/​columns/​column.component.ts Corrects width calculation and adds a non-finite fallback.
CHANGELOG.md Records the column-pinning fix.

Review effort: Balanced

@Marina-L-Stoyanova Marina-L-Stoyanova self-assigned this Nov 26, 2026
@Marina-L-Stoyanova Marina-L-Stoyanova added 💥 status: in-test PRs currently being tested ✅ status: verified Applies to PRs that have passed manual verification and removed ❌ status: awaiting-test PRs awaiting manual verification 💥 status: in-test PRs currently being tested labels Nov 26, 2026
@kdinev
kdinev requested a lite review from Copilot November 30, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The shared column-sizing changes affect Grid, Tree Grid, and Hierarchical Grid with multi-pass cache state, so approval should wait for runtime and browser-level regression coverage across grouped, percentage, hidden, pinned, and resize/reflow scenarios.

1 open issue

Review effort: Lite

@Marina-L-Stoyanova

Copy link
Copy Markdown
Contributor

After further testing I found the following gap - which is not blocking for the PR:

  1. The divide-by-zero path is still reachable through _derivePossibleWidth(). The guard was added only in cacheCalcWidth(), not in getPossibleColumnWidth() (suggestion 2 from the issue). For example, in a 1000px grid with: name width 130px publisher with minWidth="50px" and maxWidth="100px" hidden gender column without an explicit width the grid's columnWidth becomes Infinitypx, and the hidden gender column inherits the same value. If [pinned]="true" is set while gender is hidden and the column is then shown, pinned === true while pinnedColumns remains empty, reproducing the same symptom described in the issue. Handling columnsToSize === 0 in getPossibleColumnWidth() would close this remaining path.

  2. The grid's columnWidth is still ignored for columns that only define a small minWidth.
    With columnWidth="90px", such columns continue to consume the remaining available space. This behavior is unchanged by the fix, so it is probably better tracked in a separate issue.

@mddragnev mddragnev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The division by zero is still reachable as @Marina-L-Stoyanova already said. The isFinite fallback only protects cacheCalcWidth.
I'd suggest guarding the division where it happens, in getPossibleColmnWidth, and dropping the fallback in cache.
Also, please do not commit the sample that you`ve used to test the issue.
PS. I agree that the second point in Marina's comment belong in a separate issue.

@onlyexeption

Copy link
Copy Markdown
Contributor Author

Thanks @Marina-L-Stoyanova and @mddragnev, I applied the suggestion:

  • getPossibleColumnWidth() returns minColumnWidth when no visible column is left to size instead of dividing by zero.
  • The isFinite fallback in cacheCalcWidth() is removed

While testing i found that the division by zero is not limited to columns with a small minWidth. It also happens when every visible column has a width and a hidden column has none:

<igx-grid width="1000px">
    <igx-column field="name" width="200px"></igx-column>
    <igx-column field="publisher" width="200px"></igx-column>
    <igx-column field="gender" [hidden]="true" [pinned]="pinned"></igx-column>
</igx-grid>

grid.columnWidth and the width of gender return Infinitypx. When pinned is set to true and the column is then shown, pinned is true, but the column is in the unpinned area. It also reproduces on master and in the demo app. The guard fixes this case too and I added a test for it.

The widthConstrained reset and the clamped defaultWidth in cacheCalcWidth() are still needed. Without the reset, a column with minWidth="50px" gets 136px instead of 50px. Without the clamped defaultWidth, its width returns a negative value, such as -31px.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The patch changes shared width allocation and hidden-column pinning across multiple grid modes, requiring targeted browser regression coverage for multi-row layouts, resizing, and custom minimum-width cases.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@kdinev

kdinev commented Dec 3, 2026

Copy link
Copy Markdown
Member

The division by zero is still reachable as @Marina-L-Stoyanova already said. The isFinite fallback only protects cacheCalcWidth. I'd suggest guarding the division where it happens, in getPossibleColmnWidth, and dropping the fallback in cache. Also, please do not commit the sample that you`ve used to test the issue. PS. I agree that the second point in Marina's comment belong in a separate issue.

I asked for the demo update to be committed.

@mddragnev mddragnev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new regression after the last changes:

  1. A column with only a maxWidth shrinks to 136px. In a 1000px grid with a 200px column and a column with maxWidth="300px", the second column is 136px instead of 300px. It stays at 136px at any grid width, because the third branch of getConstrainedSizePx() returns minColumnWidth without clearing widthConstrained.
  2. A column held at a minWidth of 136px or more stops growing. In a 400px grid with a 200px column and a column with minWidth="300px", widening the grid to 1200px leaves the second column at 300px. On master it grows to 1000px.

Here is a patch that you can git apply for a sample that shows both issues
pr18064-column-sizing-qa.patch

mddragnev
mddragnev previously approved these changes Dec 4, 2026
@mddragnev

Copy link
Copy Markdown
Member

@onlyexeption Could you please update the 22.3 and 21.2 branches as well?

@kdinev
kdinev merged commit fe9812f into master Dec 4, 2026
7 checks passed
@kdinev
kdinev deleted the ibarakov/fix-18039 branch December 4, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

grid: column-pinning version: 22.4.x ✅ status: verified Applies to PRs that have passed manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting pinned on a column with minWidth below 136px and no width does not pin it

5 participants