Skip to content

Commit badcb07

Browse files
authored
fix(groupby): Dont set groupingExpressions if value is the same reference #9295 (#9316)
1 parent ce9a13f commit badcb07

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
@@ -358,6 +358,9 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
358358
}
359359

360360
public set groupingExpressions(value: IGroupingExpression[]) {
361+
if (this.groupingExpressions === value) {
362+
return;
363+
}
361364
if (value && value.length > 10) {
362365
throw Error('Maximum amount of grouped columns is 10.');
363366
}

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
@@ -566,6 +566,25 @@ describe('IgxGrid - GroupBy #grid', () => {
566566
}
567567
}));
568568

569+
it('should not apply grouping if the grouping expressions value is the same reference', fakeAsync(() => {
570+
const fix = TestBed.createComponent(DefaultGridComponent);
571+
fix.detectChanges();
572+
573+
// group by string column
574+
const grid = fix.componentInstance.instance;
575+
fix.detectChanges();
576+
grid.groupBy({
577+
fieldName: 'ReleaseDate', dir: SortingDirection.Asc, ignoreCase: false
578+
});
579+
fix.detectChanges();
580+
spyOn(grid.groupingExpressionsChange, 'emit');
581+
fix.detectChanges();
582+
const firstCell = grid.getCellByColumn(2, 'Downloads');
583+
UIInteractions.simulateClickAndSelectEvent(firstCell);
584+
fix.detectChanges();
585+
expect(grid.groupingExpressionsChange.emit).toHaveBeenCalledTimes(0);
586+
}));
587+
569588
// GroupBy + Sorting integration
570589
it('should apply sorting on each group\'s records when non-grouped column is sorted.', fakeAsync(() => {
571590
const fix = TestBed.createComponent(DefaultGridComponent);
@@ -3393,6 +3412,7 @@ describe('IgxGrid - GroupBy #grid', () => {
33933412
@Component({
33943413
template: `
33953414
<igx-grid
3415+
[(groupingExpressions)]='currentGroupingExpressions'
33963416
[width]='width'
33973417
[height]='height'
33983418
[dropAreaTemplate]='currentDropArea'
@@ -3421,6 +3441,7 @@ export class DefaultGridComponent extends DataParent {
34213441
public enableEditing = false;
34223442
public enableGrouping = true;
34233443
public currentSortExpressions;
3444+
public currentGroupingExpressions = [];
34243445

34253446
public columnsCreated(column: IgxColumnComponent) {
34263447
column.sortable = this.enableSorting;

0 commit comments

Comments
 (0)