Skip to content

Commit 4bcde9d

Browse files
MKirovaMKirova
authored andcommitted
fix(igxGrid): Fix and test for issue with row pinning + filtering + summaries.
1 parent 24c11a4 commit 4bcde9d

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
3333

3434
public get_summary_data() {
3535
const grid = this.grid;
36-
let data = grid.filteredData;
36+
let data = grid.unpinnedRecords;
3737
if (!data) {
3838
if (grid.transactions.enabled) {
3939
data = DataUtil.mergeTransactions(

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,17 @@ export class IgxGridRowPinningPipe implements PipeTransform {
226226

227227
public transform(collection: any[] , id: string, isPinned = false, pipeTrigger: number) {
228228
const grid = this.gridAPI.grid;
229-
230-
if (!grid.hasPinnedRecords) {
231-
return isPinned ? [] : collection;
232-
}
233-
234229
if (grid.hasPinnedRecords && isPinned) {
235230
const result = collection.filter(rec => grid.isRecordPinned(rec));
236231
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
237232
return result;
238233
}
239234

240235
grid.unpinnedRecords = collection;
236+
237+
if (!grid.hasPinnedRecords) {
238+
return isPinned ? [] : collection;
239+
}
241240
return collection.map((rec) => {
242241
return grid.isRecordPinned(rec) ? { recordRef: rec, ghostRecord: true} : rec;
243242
});

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,10 +2875,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
28752875
this.summaryService.summaryHeight = 0;
28762876
this.notifyChanges(true);
28772877
});
2878-
2879-
this.onRowPinning.subscribe(() => {
2880-
this.summaryService.clearSummaryCache();
2881-
});
28822878
}
28832879

28842880
/**

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,23 @@ describe('Row Pinning #grid', () => {
358358
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[4]);
359359
});
360360

361+
it('should calculate global summaries correctly when filtering is applied.', () => {
362+
grid.getColumnByName('ID').hasSummary = true;
363+
fix.detectChanges();
364+
grid.filter('ID', 'BERGS', IgxStringFilteringOperand.instance().condition('contains'), false);
365+
fix.detectChanges();
366+
367+
let summaryRow = GridSummaryFunctions.getRootSummaryRow(fix);
368+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 0, ['Count'], ['1']);
369+
370+
// pin row
371+
grid.getRowByIndex(0).pin();
372+
fix.detectChanges();
373+
374+
summaryRow = GridSummaryFunctions.getRootSummaryRow(fix);
375+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 0, ['Count'], ['1']);
376+
});
377+
361378
it('should remove pinned container and recalculate sizes when all pinned records are filtered out.', () => {
362379
grid.getRowByIndex(1).pin();
363380
fix.detectChanges();

src/app/grid-row-pinning/grid-row-pinning.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</igx-column>
4747
<igx-column *ngFor="let c of columns" [sortable]="true" [field]="c.field" [header]="c.field"
4848
[width]="c.width" [pinned]='c.pinned' [groupable]='c.groupable' [hidden]='c.hidden'
49-
[editable]='true'>
49+
[editable]='true' [hasSummary]='true'>
5050
</igx-column>
5151
</igx-grid>
5252
</div>
@@ -70,7 +70,7 @@
7070
<button (click)="hGrid.deleteRow(cell.cellID.rowID)">Delete</button>
7171
</ng-template>
7272
</igx-column>
73-
<igx-column *ngFor="let c of hColumns" [editable]="true" [sortable]="true" [field]="c.field" [header]="c.field" [width]="c.width" [pinned]='c.pinned' [groupable]='c.groupable' >
73+
<igx-column *ngFor="let c of hColumns" [hasSummary]='true' [editable]="true" [sortable]="true" [field]="c.field" [header]="c.field" [width]="c.width" [pinned]='c.pinned' [groupable]='c.groupable' >
7474
</igx-column>
7575
<igx-row-island [key]="'childData'" [autoGenerate]="true" [rowSelectable]='true' [allowFiltering]='true' >
7676
<igx-row-island [key]="'childData'" [autoGenerate]="true" [rowSelectable]='true' [allowFiltering]='true'></igx-row-island>

0 commit comments

Comments
 (0)