Skip to content

Commit a6f418c

Browse files
authored
fix(grid): update group summaries when new row is added via UI (#12673)
* fix(grid): trigger summary update on refresh * fix(grid): adjust pipe triggers
1 parent 9491899 commit a6f418c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4758,8 +4758,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
47584758
this.crudService.endEdit(true);
47594759
this.gridAPI.addRowToData(data);
47604760

4761-
this.rowAddedNotifier.next({ data: data, owner: this });
47624761
this.pipeTrigger++;
4762+
this.rowAddedNotifier.next({ data: data, owner: this });
47634763
this.notifyChanges();
47644764
}
47654765

@@ -5065,6 +5065,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
50655065
this.crudService.endEdit(true);
50665066
this.selectionService.clearHeaderCBState();
50675067
this.summaryService.clearSummaryCache();
5068+
this.summaryPipeTrigger++;
50685069
this.cdr.detectChanges();
50695070
}
50705071

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,57 @@ describe('IgxGrid - Summaries #grid', () => {
22842284
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 5, ['Count'], ['3']);
22852285
});
22862286

2287+
it('CRUD: Adding grouped item via UI should update group summary accordingly', () => {
2288+
grid.rowEditable = true;
2289+
fix.detectChanges();
2290+
const newRow = {
2291+
ID: 777,
2292+
ParentID: 17,
2293+
Name: 'New Employee',
2294+
HireDate: new Date(2019, 3, 3),
2295+
Age: 19,
2296+
OnPTO: true
2297+
};
2298+
const rows = grid.rowList.toArray();
2299+
rows[1].beginAddRow();
2300+
2301+
const animationElem = fix.nativeElement.querySelector('.igx-grid__tr--inner');
2302+
const endEvent = new AnimationEvent('animationend');
2303+
animationElem.dispatchEvent(endEvent);
2304+
2305+
fix.detectChanges();
2306+
2307+
let addRow = grid.gridAPI.get_row_by_index(2);
2308+
expect(addRow.addRowUI).toBeTrue();
2309+
2310+
let cell = grid.getCellByColumn(2, 'ParentID');
2311+
cell.update(newRow.ParentID);
2312+
cell = grid.getCellByColumn(2, 'Name');
2313+
cell.update(newRow.Name);
2314+
cell = grid.getCellByColumn(2, 'HireDate');
2315+
cell.update(newRow.HireDate);
2316+
cell = grid.getCellByColumn(2, 'Age');
2317+
cell.update(newRow.Age);
2318+
cell = grid.getCellByColumn(2, 'OnPTO');
2319+
cell.update(newRow.OnPTO);
2320+
2321+
fix.detectChanges();
2322+
grid.endEdit(true);
2323+
2324+
fix.detectChanges();
2325+
2326+
addRow = grid.gridAPI.get_row_by_index(2);
2327+
expect(addRow.addRowUI).toBeFalse();
2328+
2329+
let summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 4);
2330+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 0, [], []);
2331+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'Min', 'Max', 'Sum', 'Avg'], ['3', '17', '17', '51', '17']);
2332+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 2, ['Count'], ['3']);
2333+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3,
2334+
['Count', 'Earliest', 'Latest'], ['3', 'Dec 18, 2007', 'Apr 3, 2019']);
2335+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 5, ['Count'], ['3']);
2336+
});
2337+
22872338
it('CRUD: Add not grouped item', () => {
22882339
const newRow = {
22892340
ID: 777,

0 commit comments

Comments
 (0)