From 3d881e5d41578f928d1d3305aaf585c343815ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kreml=C3=A1=C4=8Dek?= Date: Wed, 10 Jan 2024 17:53:28 +0100 Subject: [PATCH 1/2] Fix #14525 reading properties of undefined during EditableColumn changes SimpleChanges might not have `data` defined when only other input than `data` changes. --- src/app/components/table/table.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index 2ede18e55d5..5d408e3d02d 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -4063,8 +4063,8 @@ export class EditableColumn implements OnChanges, AfterViewInit, OnDestroy { constructor(public dt: Table, public el: ElementRef, public zone: NgZone) {} - public ngOnChanges({ data }: SimpleChanges): void { - if (this.el.nativeElement && !data.firstChange) { + public ngOnChanges(changes: SimpleChanges): void { + if (this.el.nativeElement && (!changes.data || !changes.data.firstChange)) { this.dt.updateEditingCell(this.el.nativeElement, this.data, this.field, this.rowIndex); } } From c90ce83df545d5cb8eb8feef78664e0327790abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kreml=C3=A1=C4=8Dek?= Date: Wed, 10 Jan 2024 21:14:20 +0100 Subject: [PATCH 2/2] refactor: use optional chaining for shorter syntax --- src/app/components/table/table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index 5d408e3d02d..b883d69d3b7 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -4064,7 +4064,7 @@ export class EditableColumn implements OnChanges, AfterViewInit, OnDestroy { constructor(public dt: Table, public el: ElementRef, public zone: NgZone) {} public ngOnChanges(changes: SimpleChanges): void { - if (this.el.nativeElement && (!changes.data || !changes.data.firstChange)) { + if (this.el.nativeElement && (!changes.data?.firstChange)) { this.dt.updateEditingCell(this.el.nativeElement, this.data, this.field, this.rowIndex); } }