Skip to content

Commit be244a8

Browse files
authored
fix(groupby): Dont set groupingExpressions if value is the same reference #9295 (#9317)
1 parent 6c3482b commit be244a8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
223223
}
224224

225225
set groupingExpressions(value: IGroupingExpression[]) {
226+
if (this.groupingExpressions === value) {
227+
return;
228+
}
226229
if (value && value.length > 10) {
227230
throw Error('Maximum amount of grouped columns is 10.');
228231
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,25 @@ describe('IgxGrid - GroupBy #grid', () => {
565565
}
566566
}));
567567

568+
it('should not apply grouping if the grouping expressions value is the same reference', fakeAsync(() => {
569+
const fix = TestBed.createComponent(DefaultGridComponent);
570+
fix.detectChanges();
571+
572+
// group by string column
573+
const grid = fix.componentInstance.instance;
574+
fix.detectChanges();
575+
grid.groupBy({
576+
fieldName: 'ReleaseDate', dir: SortingDirection.Asc, ignoreCase: false
577+
});
578+
fix.detectChanges();
579+
spyOn(grid.groupingExpressionsChange, 'emit');
580+
fix.detectChanges();
581+
const firstCell = grid.getCellByColumn(2, 'Downloads');
582+
UIInteractions.simulateClickAndSelectEvent(firstCell);
583+
fix.detectChanges();
584+
expect(grid.groupingExpressionsChange.emit).toHaveBeenCalledTimes(0);
585+
}));
586+
568587
// GroupBy + Sorting integration
569588
it('should apply sorting on each group\'s records when non-grouped column is sorted.', fakeAsync(() => {
570589
const fix = TestBed.createComponent(DefaultGridComponent);
@@ -2620,6 +2639,7 @@ describe('IgxGrid - GroupBy #grid', () => {
26202639
@Component({
26212640
template: `
26222641
<igx-grid
2642+
[(groupingExpressions)]='currentGroupingExpressions'
26232643
[width]='width'
26242644
[height]='height'
26252645
[dropAreaTemplate]='currentDropArea'
@@ -2648,6 +2668,7 @@ export class DefaultGridComponent extends DataParent {
26482668
public enableEditing = false;
26492669
public enableGrouping = true;
26502670
public currentSortExpressions;
2671+
public currentGroupingExpressions = [];
26512672

26522673
public columnsCreated(column: IgxColumnComponent) {
26532674
column.sortable = this.enableSorting;

0 commit comments

Comments
 (0)