Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #15852 - Table: Frozen columns are displaced #15854

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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