From 13cf724095cec2b1d9719acf2367b774a4d87667 Mon Sep 17 00:00:00 2001 From: Ondrej Skotnica Date: Tue, 30 Jan 2024 14:32:16 +0100 Subject: [PATCH] Table | Row Expansion and Selection not Working Together #14081 --- src/app/components/table/table.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index 3071cda3779..04c2e982142 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -2426,11 +2426,13 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable } toggleRow(rowData: any, event?: Event) { - if (!this.dataKey) { - throw new Error('dataKey must be defined to use row expansion'); + if (!this.dataKey && !this.groupRowsBy) { + throw new Error('dataKey or groupRowsBy must be defined to use row expansion'); } - let dataKeyValue = String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); + let dataKeyValue = this.groupRowsBy ? + String(ObjectUtils.resolveFieldData(rowData, this.groupRowsBy)) : + String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); if (this.expandedRowKeys[dataKeyValue] != null) { delete this.expandedRowKeys[dataKeyValue]; @@ -2460,7 +2462,9 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable } isRowExpanded(rowData: any): boolean { - return this.expandedRowKeys[String(ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true; + return this.groupRowsBy ? + this.expandedRowKeys[String(ObjectUtils.resolveFieldData(rowData, this.groupRowsBy))] === true : + this.expandedRowKeys[String(ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true; } isRowEditing(rowData: any): boolean {