Skip to content

Commit 0f0b5a4

Browse files
authored
Merge pull request #13589 from IgniteUI/mkirkova/fix-13514-16.1.x
Return updated values when groupingDone is emitted
2 parents 96f899c + c45cb06 commit 0f0b5a4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export class IgxGrouping extends IgxSorting implements IGridGroupingStrategy {
258258
groupsRecords?: any[], fullResult: IGroupByResult = { data: [], metadata: [] }): IGroupByResult {
259259
const metadata: IGroupByRecord[] = [];
260260
const grouping = this.groupDataRecursive(data, state, 0, null, metadata, grid, groupsRecords, fullResult);
261+
grid?.groupingPerformedSubject.next();
261262
return {
262263
data: grouping,
263264
metadata

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IgxGridGroupByRowComponent } from './groupby-row.component';
1515
import { IGroupByExpandState } from '../../data-operations/groupby-expand-state.interface';
1616
import { IForOfState, IgxGridForOfDirective } from '../../directives/for-of/for_of.directive';
1717
import { IgxColumnComponent } from '../columns/column.component';
18-
import { takeUntil } from 'rxjs/operators';
18+
import { take, takeUntil } from 'rxjs/operators';
1919
import { IgxFilteringService } from '../filtering/grid-filtering.service';
2020
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
2121
import { IgxColumnResizingService } from '../resizing/resizing.service';
@@ -53,6 +53,7 @@ import { IgxGridDragSelectDirective } from '../selection/drag-select.directive';
5353
import { IgxGridBodyDirective } from '../grid.common';
5454
import { IgxGridHeaderRowComponent } from '../headers/grid-header-row.component';
5555
import { IgxGridGroupByAreaComponent } from '../grouping/grid-group-by-area.component';
56+
import { Observable, Subject } from 'rxjs';
5657

5758
let NEXT_ID = 0;
5859

@@ -425,6 +426,16 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
425426

426427
private childDetailTemplates: Map<any, any> = new Map();
427428

429+
/**
430+
* @hidden @internal
431+
*/
432+
public groupingPerformedSubject = new Subject<void>();
433+
434+
/**
435+
* @hidden @internal
436+
*/
437+
public groupingPerformed$: Observable<void> = this.groupingPerformedSubject.asObservable();
438+
428439
/**
429440
* Gets/Sets the group by state.
430441
*
@@ -478,7 +489,9 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
478489
groupedColumns: groupedCols,
479490
ungroupedColumns: ungroupedCols
480491
};
481-
this.groupingDone.emit(groupingDoneArgs);
492+
this.groupingPerformed$.pipe(take(1)).subscribe(() => {
493+
this.groupingDone.emit(groupingDoneArgs);
494+
});
482495
}
483496
}
484497

@@ -739,6 +752,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
739752
this._gridAPI.clear_groupby(name);
740753
this.calculateGridSizes();
741754
this.notifyChanges(true);
755+
this.groupingPerformedSubject.next();
742756
}
743757

744758
/**

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,30 @@ describe('IgxGrid - GroupBy #grid', () => {
712712
expect(currExpr.groupedColumns[0].field).toEqual('Downloads');
713713
}));
714714

715+
it('should update groupsRecords when groupingDone is emitted', fakeAsync(() => {
716+
const fix = TestBed.createComponent(DefaultGridComponent);
717+
const grid = fix.componentInstance.instance;
718+
fix.detectChanges();
719+
720+
let groupsRecordsLength;
721+
722+
spyOn(grid.groupingDone, 'emit').and.callThrough();
723+
grid.groupingDone.subscribe(() => {
724+
groupsRecordsLength = grid.groupsRecords.length;
725+
});
726+
grid.groupBy({
727+
fieldName: 'ProductName', dir: SortingDirection.Desc, ignoreCase: false
728+
});
729+
tick();
730+
fix.detectChanges();
731+
expect(groupsRecordsLength).toEqual(5);
732+
733+
grid.clearGrouping();
734+
tick();
735+
fix.detectChanges();
736+
expect(groupsRecordsLength).toEqual(0);
737+
}));
738+
715739
it('should allow setting custom template for group row content and expand/collapse icons.', fakeAsync(() => {
716740
const fix = TestBed.createComponent(CustomTemplateGridComponent);
717741
const grid = fix.componentInstance.instance;

0 commit comments

Comments
 (0)