Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13783 and #14081 - Table | expandable groups broken with paginator, Expansion and Selection not Working Together #14672

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -3168,7 +3172,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 @@ -3179,7 +3183,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