Skip to content

Commit cefe762

Browse files
authored
fix(groupby): adding proper comparison function to determine expansion state (#12869)
1 parent 2435514 commit cefe762

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

projects/igniteui-angular/src/lib/data-operations/data-util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
IgxGrouping
2020
} from '../grids/common/strategy';
2121
import { DefaultDataCloneStrategy, IDataCloneStrategy } from '../data-operations/data-clone-strategy';
22+
import { IGroupingExpression } from './grouping-expression.interface';
2223

2324
/**
2425
* @hidden
@@ -132,8 +133,8 @@ export class DataUtil {
132133
return getHierarchy(gRow);
133134
}
134135

135-
public static isHierarchyMatch(h1: Array<IGroupByKey>, h2: Array<IGroupByKey>): boolean {
136-
return isHierarchyMatch(h1, h2);
136+
public static isHierarchyMatch(h1: Array<IGroupByKey>, h2: Array<IGroupByKey>, expressions: IGroupingExpression[]): boolean {
137+
return isHierarchyMatch(h1, h2, expressions);
137138
}
138139

139140
/**

projects/igniteui-angular/src/lib/data-operations/operations.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { IGroupByKey } from './groupby-expand-state.interface';
22
import { IGroupByRecord } from './groupby-record.interface';
3+
import { IGroupingExpression } from './grouping-expression.interface';
4+
import { DefaultSortingStrategy } from './sorting-strategy';
35

4-
export const isHierarchyMatch = (h1: Array<IGroupByKey>, h2: Array<IGroupByKey>): boolean => {
6+
export const isHierarchyMatch = (h1: Array<IGroupByKey>, h2: Array<IGroupByKey>, expressions: IGroupingExpression[]): boolean => {
57
if (h1.length !== h2.length) {
68
return false;
79
}
8-
return h1.every((level, index): boolean => level.fieldName === h2[index].fieldName && level.value === h2[index].value);
10+
return h1.every((level, index): boolean => {
11+
const expr = expressions.find(e => e.fieldName === level.fieldName);
12+
const comparer = expr.groupingComparer || DefaultSortingStrategy.instance().compareValues;
13+
return level.fieldName === h2[index].fieldName && comparer(level.value, h2[index].value) === 0;
14+
});
915
};
1016

1117
export const getHierarchy = (gRow: IGroupByRecord): Array<IGroupByKey> => {

projects/igniteui-angular/src/lib/grids/common/strategy.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export class IgxSorting implements IGridSortingStrategy {
6363
}
6464
const hierarchy = getHierarchy(groupRow);
6565
const expandState: IGroupByExpandState = expansion.find((s) =>
66-
isHierarchyMatch(s.hierarchy || [{ fieldName: groupRow.expression.fieldName, value: groupRow.value }], hierarchy));
66+
isHierarchyMatch(
67+
s.hierarchy || [{ fieldName: groupRow.expression.fieldName, value: groupRow.value }],
68+
hierarchy,
69+
expressions
70+
));
6771
const expanded = expandState ? expandState.expanded : state.defaultExpanded;
6872
let recursiveResult;
6973
result.push(groupRow);

projects/igniteui-angular/src/lib/grids/grid/grid-api.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export class IgxGridAPIService extends GridBaseAPIService<GridType> implements G
5858
const grState = this.grid.groupingExpansionState;
5959
const hierarchy = DataUtil.getHierarchy(groupRow);
6060
return grState.find((state) =>
61-
DataUtil.isHierarchyMatch(state.hierarchy || [{ fieldName: groupRow.expression.fieldName, value: groupRow.value }], hierarchy));
61+
DataUtil.isHierarchyMatch(
62+
state.hierarchy || [{ fieldName: groupRow.expression.fieldName, value: groupRow.value }],
63+
hierarchy,
64+
this.grid.groupingExpressions));
6265
}
6366

6467
public groupBy_is_row_in_group(groupRow: IGroupByRecord, rowID): boolean {

projects/igniteui-angular/src/lib/grids/grid/grid.groupby.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ describe('IgxGrid - GroupBy #grid', () => {
467467
tick();
468468
fix.detectChanges();
469469
expect(groupRow.expanded).toBe(false);
470+
471+
grid.clearGrouping();
472+
tick();
473+
grid.groupBy({ fieldName: 'ReleaseDate', dir: SortingDirection.Desc });
474+
fix.detectChanges();
475+
grid.toggleGroup(grid.groupsRowList.first.groupRow);
476+
tick();
477+
fix.detectChanges();
478+
expect(groupRows[0].expanded).toEqual(false);
470479
}));
471480

472481
it('should allow changing the order of the groupBy columns.', fakeAsync(() => {

projects/igniteui-angular/src/lib/services/exporter-common/base-export-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,9 @@ export abstract class IgxBaseExporter {
10281028
const hierarchicalOwner = setGridParent ? GRID_PARENT : `${GRID_CHILD}${++this.rowIslandCounter}`;
10291029
const hierarchy = getHierarchy(record);
10301030
const expandState: IGroupByExpandState = groupingState.expansion.find((s) =>
1031-
isHierarchyMatch(s.hierarchy || [{ fieldName: record.expression.fieldName, value: recordVal }], hierarchy));
1031+
isHierarchyMatch(s.hierarchy || [{ fieldName: record.expression.fieldName, value: recordVal }],
1032+
hierarchy,
1033+
grid.groupingExpressions));
10321034
const expanded = expandState ? expandState.expanded : groupingState.defaultExpanded;
10331035

10341036
const isDate = recordVal instanceof Date;

0 commit comments

Comments
 (0)