Skip to content

Commit

Permalink
Fixed primefaces#15852 - Table: Frozen columns are displaced
Browse files Browse the repository at this point in the history
  • Loading branch information
ranthonissen committed Jun 17, 2024
1 parent fadc0f9 commit 68bce16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
19 changes: 6 additions & 13 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand All @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/app/showcase/doc/table/frozencolumnsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CustomerService } from '@service/customerservice';
<ng-template pTemplate="header">
<tr>
<th style="min-width:200px" pFrozenColumn>Name</th>
<th style="min-width:100px">Id</th>
<th style="min-width:100px" pFrozenColumn>Id</th>
<th style="min-width:200px">Country</th>
<th style="min-width:200px">Date</th>
<th style="min-width:200px">Company</th>
Expand All @@ -29,7 +29,7 @@ import { CustomerService } from '@service/customerservice';
<ng-template pTemplate="body" let-customer>
<tr>
<td pFrozenColumn>{{ customer.name }}</td>
<td style="min-width:100px">{{ customer.id }}</td>
<td pFrozenColumn style="min-width:100px">{{ customer.id }}</td>
<td>{{ customer.country.name }}</td>
<td>{{ customer.date }}</td>
<td>{{ customer.company }}</td>
Expand Down Expand Up @@ -67,11 +67,11 @@ export class FrozenColumnsDoc {
}

code: Code = {
basic: `<p-toggleButton
[(ngModel)]="balanceFrozen"
basic: `<p-toggleButton
[(ngModel)]="balanceFrozen"
[onIcon]="'pi pi-lock'"
offIcon="pi pi-lock-open"
[onLabel]="'Balance'"
offIcon="pi pi-lock-open"
[onLabel]="'Balance'"
offLabel="Balance" />
<p-table [value]="customers" [scrollable]="true" scrollHeight="400px" styleClass="mt-3">
Expand Down Expand Up @@ -103,10 +103,10 @@ export class FrozenColumnsDoc {
</ng-template>
</p-table>`,
html: `<div class="card">
<p-toggleButton
[(ngModel)]="balanceFrozen"
[onIcon]="'pi pi-lock'"
offIcon="pi pi-lock-open"
<p-toggleButton
[(ngModel)]="balanceFrozen"
[onIcon]="'pi pi-lock'"
offIcon="pi pi-lock-open"
[onLabel]="'Balance'"
offLabel="Balance" />
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 68bce16

Please sign in to comment.