From 68bce167f88870df4a14485a89654e17dfd38a34 Mon Sep 17 00:00:00 2001 From: Ronald Anthonissen Date: Mon, 17 Jun 2024 16:19:26 +0200 Subject: [PATCH] Fixed #15852 - Table: Frozen columns are displaced --- src/app/components/table/table.ts | 19 +++++----------- .../showcase/doc/table/frozencolumnsdoc.ts | 22 +++++++++---------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index b15d650b46b..28049698e58 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -2,6 +2,7 @@ import { animate, AnimationEvent, style, transition, trigger } from '@angular/an import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common'; import { AfterContentInit, + AfterViewChecked, AfterViewInit, booleanAttribute, ChangeDetectionStrategy, @@ -3301,14 +3302,14 @@ export class RowGroupHeader { '[class.p-frozen-column]': 'frozen' } }) -export class FrozenColumn implements AfterViewInit { +export class FrozenColumn implements AfterViewChecked { @Input() get frozen(): boolean { return this._frozen; } set frozen(val: boolean) { this._frozen = val; - Promise.resolve(null).then(() => this.updateStickyPosition()); + this.updateStickyPosition(); } @Input() alignFrozen: string = 'left'; @@ -3318,23 +3319,15 @@ export class FrozenColumn implements AfterViewInit { private zone: NgZone ) {} - ngAfterViewInit() { + ngAfterViewChecked() { this.zone.runOutsideAngular(() => { - setTimeout(() => { - this.recalculateColumns(); - }, 1000); + this.recalculateColumns(); }); } @HostListener('window:resize', ['$event']) recalculateColumns() { - const siblings = DomHandler.siblings(this.el.nativeElement); - const index = DomHandler.index(this.el.nativeElement); - const time = (siblings.length - index + 1) * 50; - - setTimeout(() => { - this.updateStickyPosition(); - }, time); + this.updateStickyPosition(); } _frozen: boolean = true; diff --git a/src/app/showcase/doc/table/frozencolumnsdoc.ts b/src/app/showcase/doc/table/frozencolumnsdoc.ts index b0ff2732365..2c3cbaca2ca 100644 --- a/src/app/showcase/doc/table/frozencolumnsdoc.ts +++ b/src/app/showcase/doc/table/frozencolumnsdoc.ts @@ -16,7 +16,7 @@ import { CustomerService } from '@service/customerservice'; Name - Id + Id Country Date Company @@ -29,7 +29,7 @@ import { CustomerService } from '@service/customerservice'; {{ customer.name }} - {{ customer.id }} + {{ customer.id }} {{ customer.country.name }} {{ customer.date }} {{ customer.company }} @@ -67,11 +67,11 @@ export class FrozenColumnsDoc { } code: Code = { - basic: ` @@ -103,10 +103,10 @@ export class FrozenColumnsDoc { `, html: `
- @@ -177,7 +177,7 @@ export class TableFrozenColumnsDemo implements OnInit{ formatCurrency(value: number) { return value.toLocaleString('en-US', { style: 'currency', currency: 'USD' }); - } + } }`, scss: ` :host ::ng-deep .p-frozen-column {