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

fix(datagrid): remove setTimeout and check visibility for calculations #1577

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion projects/angular/clarity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5257,7 +5257,7 @@ export class ÇlrDatagridHeaderRenderer implements OnDestroy {

// @public (undocumented)
export class ÇlrDatagridMainRenderer implements AfterContentInit, AfterViewInit, AfterViewChecked, OnDestroy {
constructor(organizer: DatagridRenderOrganizer, items: Items, page: Page, el: ElementRef<HTMLElement>, renderer: Renderer2, detailService: DetailService, tableSizeService: TableSizeService, columnsService: ColumnsService, ngZone: NgZone, keyNavigation: KeyNavigationGridController);
constructor(datagrid: ClrDatagrid, organizer: DatagridRenderOrganizer, items: Items, page: Page, el: ElementRef<HTMLElement>, renderer: Renderer2, detailService: DetailService, tableSizeService: TableSizeService, columnsService: ColumnsService, ngZone: NgZone, keyNavigation: KeyNavigationGridController);
// (undocumented)
ngAfterContentInit(): void;
// (undocumented)
Expand Down
19 changes: 15 additions & 4 deletions projects/angular/src/data/datagrid/render/main-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { Subscription } from 'rxjs';

import { DomAdapter } from '../../../utils/dom-adapter/dom-adapter';
import { ClrDatagrid } from '../datagrid';
import { DatagridColumnChanges } from '../enums/column-changes.enum';
import { DatagridRenderStep } from '../enums/render-step.enum';
import { ColumnStateDiff } from '../interfaces/column-state.interface';
Expand Down Expand Up @@ -68,6 +69,7 @@ export class DatagridMainRenderer implements AfterContentInit, AfterViewInit, Af
private columnsSizesStable = false;

constructor(
private datagrid: ClrDatagrid,
private organizer: DatagridRenderOrganizer,
private items: Items,
private page: Page,
Expand Down Expand Up @@ -118,10 +120,9 @@ export class DatagridMainRenderer implements AfterContentInit, AfterViewInit, Af
}

ngAfterViewChecked() {
if (this.shouldStabilizeColumns) {
setTimeout(() => {
this.stabilizeColumns();
}, 0);
const datagridIsVisible = this.checkAndUpdateVisibility();
if (this.shouldStabilizeColumns && datagridIsVisible) {
this.stabilizeColumns();
}

if (this.shouldComputeHeight()) {
Expand Down Expand Up @@ -284,4 +285,14 @@ export class DatagridMainRenderer implements AfterContentInit, AfterViewInit, Af
this.columnsSizesStable = true;
}
}

private checkAndUpdateVisibility() {
if (this.el.nativeElement.offsetParent) {
this.datagrid.datagrid.nativeElement.style.visibility = 'visible';
dtsanevmw marked this conversation as resolved.
Show resolved Hide resolved
dtsanevmw marked this conversation as resolved.
Show resolved Hide resolved
return true;
} else {
this.datagrid.datagrid.nativeElement.style.visibility = 'hidden';
return false;
}
}
}
Loading