Skip to content

Commit

Permalink
Merge pull request #14672 from Fraser12345/master
Browse files Browse the repository at this point in the history
Fix #13783 and #14081 - Table | expandable groups broken with paginator, Expansion and Selection not Working Together
  • Loading branch information
cetincakiroglu authored Mar 20, 2024
2 parents c89e282 + c441142 commit 2f92b7b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2428,11 +2428,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];
Expand Down Expand Up @@ -2462,7 +2464,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 {
Expand Down Expand Up @@ -3182,7 +3186,7 @@ export class TableBody implements AfterViewInit, OnDestroy {

shouldRenderRowGroupHeader(value: any, rowData: any, i: number) {
let currentRowFieldData = ObjectUtils.resolveFieldData(rowData, this.dt.groupRowsBy);
let prevRowData = value[i - 1];
let prevRowData = value[i - (1 + this.dt._first)];
if (prevRowData) {
let previousRowFieldData = ObjectUtils.resolveFieldData(prevRowData, this.dt.groupRowsBy);
return currentRowFieldData !== previousRowFieldData;
Expand All @@ -3193,7 +3197,7 @@ export class TableBody implements AfterViewInit, OnDestroy {

shouldRenderRowGroupFooter(value: any, rowData: any, i: number) {
let currentRowFieldData = ObjectUtils.resolveFieldData(rowData, this.dt.groupRowsBy);
let nextRowData = value[i + 1];
let nextRowData = value[i + (1 + this.dt._first)];
if (nextRowData) {
let nextRowFieldData = ObjectUtils.resolveFieldData(nextRowData, this.dt.groupRowsBy);
return currentRowFieldData !== nextRowFieldData;
Expand Down

0 comments on commit 2f92b7b

Please sign in to comment.