From 8950ec3720e4220b830a591261f4579e7fea42c2 Mon Sep 17 00:00:00 2001 From: Karl Seamon Date: Fri, 24 Jan 2025 11:38:51 -0500 Subject: [PATCH] fix(cdk/table): Column sizing and scrolling bug when number of columns in table changes (#30378) Part of fix includes cdk-experimental/column-resize. See internal issue 390466445. --- src/cdk-experimental/column-resize/resize-strategy.ts | 5 +++++ src/cdk/table/sticky-styler.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cdk-experimental/column-resize/resize-strategy.ts b/src/cdk-experimental/column-resize/resize-strategy.ts index a37ea5db0b43..372e35baa659 100644 --- a/src/cdk-experimental/column-resize/resize-strategy.ts +++ b/src/cdk-experimental/column-resize/resize-strategy.ts @@ -65,6 +65,11 @@ export abstract class ResizeStrategy implements OnDestroy { }); this.styleScheduler.scheduleEnd(() => { + // Once the column sizes have updated, we unset the table width so that + // it does not have unwanted side effects on future changes in the table + // such as columns being added or removed. + tableElement.style.width = ''; + this.table.updateStickyColumnStyles(); }); } diff --git a/src/cdk/table/sticky-styler.ts b/src/cdk/table/sticky-styler.ts index cdf8a9569803..eebe0b8ec3ea 100644 --- a/src/cdk/table/sticky-styler.ts +++ b/src/cdk/table/sticky-styler.ts @@ -185,7 +185,7 @@ export class StickyStyler { } } - if (this._positionListener) { + if (this._positionListener && cellWidths.some(w => !!w)) { this._positionListener.stickyColumnsUpdated({ sizes: lastStickyStart === -1