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 {