diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts index fcf804821b1..1358c14418e 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts @@ -287,6 +287,37 @@ describe('IgxGrid - Summaries #grid', () => { 'summary cell and data cell are not right aligned'); })); + it('should be able to access alldata from each summary', fakeAsync(() => { + const fixture = TestBed.createComponent(CustomSummariesComponent); + const grid = fixture.componentInstance.grid1; + fixture.detectChanges(); + + const summaryRow = fixture.debugElement.query(By.css(SUMMARY_ROW)); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Sum', 'Avg'], ['10', '39,004', '3,900.4']); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']); + GridSummaryFunctions.verifyVisibleSummariesHeight(fixture, 3, grid.defaultSummaryHeight); + grid.getColumnByName('UnitsInStock').summaries = fixture.componentInstance.inStockSummary; + tick(100); + fixture.detectChanges(); + + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'], + ['10', '0', '20,000', '39,004', '3,900.4', '6']); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']); + + grid.getCellByColumn(4, 'InStock').update(true); + tick(); + fixture.detectChanges(); + + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'], + ['10', '0', '20,000', '39,004', '3,900.4', '7']); + + grid.filter('UnitsInStock', 0, IgxNumberFilteringOperand.instance().condition('equals')); + fixture.detectChanges(); + + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'], + ['3', '0', '0', '0', '0', '1']); + })); + describe('', () => { let fix; let grid: IgxGridComponent; @@ -2441,6 +2472,24 @@ class EarliestSummary extends IgxDateSummaryOperand { } } +class InStockSummary extends IgxNumberSummaryOperand { + constructor() { + super(); + } + + public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] { + const result = super.operate(summaries); + if (field && field === 'UnitsInStock') { + result.push({ + key: 'test', + label: 'Items InStock', + summaryResult: allData.filter((rec) => rec.InStock).length + }); + } + return result; + } +} + @Component({ template: ` @@ -2466,6 +2515,7 @@ export class CustomSummariesComponent { public dealsSummary = DealsSummary; public dealsSummaryMinMax = DealsSummaryMinMax; public earliest = EarliestSummary; + public inStockSummary = InStockSummary; } @Component({ diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-summaries.spec.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-summaries.spec.ts index ef6f1bcb8ac..06b9eaa3dfd 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-summaries.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-summaries.spec.ts @@ -1609,6 +1609,44 @@ describe('IgxTreeGrid - Summaries #tGrid', () => { verifySummaryForRow847(fix, 6); })); + it('should be able to access alldata from each summary', fakeAsync(() => { + const fix = TestBed.createComponent(IgxTreeGridCustomSummariesComponent); + fix.detectChanges(); + const treeGrid = fix.componentInstance.treeGrid; + + treeGrid.expandAll(); + fix.detectChanges(); + + let summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['2']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['3']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['4']); + + treeGrid.getColumnByName('Name').summaries = fix.componentInstance.ptoSummary; + tick(); + fix.detectChanges(); + + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '1']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']); + + treeGrid.getCellByColumn(5, 'OnPTO').update(true); + tick(); + fix.detectChanges(); + + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '2']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']); + summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0); + GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']); + })); + it('should render rows correctly after collapse and expand', async () => { const fix = TestBed.createComponent(IgxTreeGridSummariesScrollingComponent); const treeGrid = fix.componentInstance.treeGrid; diff --git a/projects/igniteui-angular/src/lib/test-utils/tree-grid-components.spec.ts b/projects/igniteui-angular/src/lib/test-utils/tree-grid-components.spec.ts index 25fd0d69115..48c07b47d47 100644 --- a/projects/igniteui-angular/src/lib/test-utils/tree-grid-components.spec.ts +++ b/projects/igniteui-angular/src/lib/test-utils/tree-grid-components.spec.ts @@ -1,7 +1,7 @@ import { Component, ViewChild, OnInit } from '@angular/core'; import { IgxTreeGridComponent } from '../grids/tree-grid/tree-grid.component'; import { SampleTestData } from './sample-test-data.spec'; -import { IgxNumberSummaryOperand, IgxSummaryResult } from '../grids'; +import { IgxSummaryOperand, IgxNumberSummaryOperand, IgxSummaryResult } from '../grids'; import { IgxGridTransaction } from '../grids/grid-base.component'; import { IgxTransactionService } from '../services/transaction/igx-transaction'; import { IgxHierarchicalTransactionService } from '../services/transaction/igx-hierarchical-transaction'; @@ -400,6 +400,24 @@ class AgeSummaryTest extends IgxNumberSummaryOperand { } } +class PTOSummary extends IgxSummaryOperand { + constructor() { + super(); + } + + public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] { + const result = super.operate(summaries); + if (field && field === 'Name') { + result.push({ + key: 'test', + label: 'People on PTO', + summaryResult: allData.filter((rec) => rec.OnPTO).length + }); + } + return result; + } +} + @Component({ template: ` @@ -433,6 +451,7 @@ export class IgxTreeGridCustomSummariesComponent { public data = SampleTestData.employeeTreeData(); public ageSummary = AgeSummary; public ageSummaryTest = AgeSummaryTest; + public ptoSummary = PTOSummary; } @Component({