From ccbef9d57d62392841bb84f79a930e4d4d0a6175 Mon Sep 17 00:00:00 2001 From: Kisters-BS <84901454+Kisters-BS@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:38:23 +0200 Subject: [PATCH] Fix check containerViewChild for undefined in saveColumnWidths --- src/app/components/table/table.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index bbda2848090..bac0879007a 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -2908,7 +2908,13 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable saveColumnWidths(state: any) { let widths: any[] = []; - let headers = DomHandler.find(this.containerViewChild?.nativeElement, '.p-datatable-thead > tr > th'); + let headers = []; + const container = this.containerViewChild?.nativeElement; + + if (container) { + headers = DomHandler.find(container, '.p-datatable-thead > tr > th'); + } + headers.forEach((header) => widths.push(DomHandler.getOuterWidth(header))); state.columnWidths = widths.join(',');