Skip to content

Commit 5720259

Browse files
committed
chore(*): add additional logic to selectedRows getter
1 parent a118c18 commit 5720259

File tree

3 files changed

+65
-31
lines changed

3 files changed

+65
-31
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { DataUtil } from '../../data-operations/data-util';
6161
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
6262
import { IgxGridTransaction } from '../common/types';
6363
import { SortingDirection } from '../../data-operations/sorting-strategy';
64-
import { IgxGridAPIService } from '../grid/grid-api.service';
6564
import { GridBaseAPIService } from '../api.service';
6665

6766
let NEXT_ID = 0;
@@ -412,8 +411,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
412411
this.dataView.forEach(record => {
413412
const prev = [];
414413
for (const dim of this.rowDimensions) {
415-
const key = PivotUtil.getRecordKey(record, dim, prev);
416-
prev.push(dim);
414+
const currDim = record[dim.memberName] ? dim : record[dim.childLevel.memberName] ? dim.childLevel : dim;
415+
const key = PivotUtil.getRecordKey(record, currDim, prev);
416+
prev.push(currDim);
417417
if (this.selectionService.isPivotRowSelected(key) && !selectedRowIds.find(x => x === record)) {
418418
selectedRowIds.push(record);
419419
break;

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
7979
checkboxes[1].click();
8080
fixture.detectChanges();
8181

82-
// uncheck Bikes
82+
// uncheck Bikes
8383
checkboxes[2].click();
8484
fixture.detectChanges();
8585

@@ -109,19 +109,19 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
109109
checkboxes[1].click();
110110
fixture.detectChanges();
111111

112-
// uncheck Uruguay
112+
// uncheck Uruguay
113113
checkboxes[2].click();
114114
fixture.detectChanges();
115115

116116

117-
// Click 'apply' button to apply filter.
118-
GridFunctions.clickApplyExcelStyleFiltering(fixture, excelMenu, 'igx-pivot-grid');
119-
fixture.detectChanges();
117+
// Click 'apply' button to apply filter.
118+
GridFunctions.clickApplyExcelStyleFiltering(fixture, excelMenu, 'igx-pivot-grid');
119+
fixture.detectChanges();
120120

121-
// check columns
122-
const colHeaders = pivotGrid.columns.filter(x => x.level === 0).map(x => x.header);
123-
const expected = ['USA'];
124-
expect(colHeaders).toEqual(expected);
121+
// check columns
122+
const colHeaders = pivotGrid.columns.filter(x => x.level === 0).map(x => x.header);
123+
const expected = ['USA'];
124+
expect(colHeaders).toEqual(expected);
125125
});
126126

127127
it('should apply sorting for dimension via row chip', () => {
@@ -207,14 +207,14 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
207207
aggregator: IgxTotalSaleAggregate.totalSale,
208208
label: 'Sum of Sale'
209209
}, {
210-
key: 'MIN',
211-
aggregator: IgxTotalSaleAggregate.totalMin,
212-
label: 'Minimum of Sale'
213-
}, {
214-
key: 'MAX',
215-
aggregator: IgxTotalSaleAggregate.totalMax,
216-
label: 'Maximum of Sale'
217-
}],
210+
key: 'MIN',
211+
aggregator: IgxTotalSaleAggregate.totalMin,
212+
label: 'Minimum of Sale'
213+
}, {
214+
key: 'MAX',
215+
aggregator: IgxTotalSaleAggregate.totalMax,
216+
label: 'Maximum of Sale'
217+
}],
218218
enabled: true
219219
});
220220
pivotGrid.pipeTrigger++;
@@ -274,8 +274,10 @@ describe('IgxPivotGrid complex hierarchy #pivotGrid', () => {
274274
const expected =
275275
{
276276
'All cities': 'All Cities', 'All cities_level': 0,
277-
ProductCategory: 'Bikes', ProductCategory_level: 1,
278-
'Uruguay-AmountOfSale': 242.08, 'Uruguay-UnitsSold': 68
277+
ProductCategory: 'Clothing', ProductCategory_level: 1,
278+
'Bulgaria-AmountOfSale': 3612.42, 'Bulgaria-UnitsSold': 282,
279+
'US-AmountOfSale': 14672.72, 'US-UnitsSold': 296,
280+
'Uruguay-AmountOfSale': 31158.48, 'Uruguay-UnitsSold': 456
279281
};
280282
expect(pivotGrid.selectedRows[0]).toEqual(expected);
281283

@@ -303,25 +305,28 @@ describe('IgxPivotGrid complex hierarchy #pivotGrid', () => {
303305
{
304306
AllProducts: 'AllProducts', 'All cities': 'All Cities',
305307
'All cities_level': 0, AllProducts_level: 0, 'Bulgaria-UnitsSold': 774,
306-
'Bulgaria-AmountOfSale': 11509.02, 'USA-UnitsSold': 829, 'USA-AmountOfSale': 44098.85999999999,
307-
'Uruguay-UnitsSold': 524, 'Uruguay-AmountOfSale': 31400.56
308-
}, {
309-
ProductCategory: 'Clothing', 'All cities': 'All Cities',
310-
ProductCategory_level: 1, 'All cities_level': 0, 'Bulgaria-UnitsSold': 774,
311-
'Bulgaria-AmountOfSale': 11509.02, 'USA-UnitsSold': 296, 'USA-AmountOfSale': 14672.72,
312-
'Uruguay-UnitsSold': 456, 'Uruguay-AmountOfSale': 31158.48
308+
'Bulgaria-AmountOfSale': 11509.02, 'US-UnitsSold': 296, 'US-AmountOfSale': 14672.72,
309+
'Uruguay-UnitsSold': 524, 'Uruguay-AmountOfSale': 31400.56,
310+
'UK-UnitsSold': 293, 'UK-AmountOfSale': 25074.94,
311+
'Japan-UnitsSold': 240, 'Japan-AmountOfSale': 4351.2,
313312
}, {
314313
ProductCategory: 'Bikes', 'All cities': 'All Cities',
315314
ProductCategory_level: 1, 'All cities_level': 0,
316315
'Uruguay-UnitsSold': 68, 'Uruguay-AmountOfSale': 242.08
316+
}, {
317+
ProductCategory: 'Clothing', 'All cities': 'All Cities',
318+
ProductCategory_level: 1, 'All cities_level': 0, 'Bulgaria-UnitsSold': 282,
319+
'Bulgaria-AmountOfSale': 3612.42, 'US-UnitsSold': 296, 'US-AmountOfSale': 14672.72,
320+
'Uruguay-UnitsSold': 456, 'Uruguay-AmountOfSale': 31158.48
317321
}, {
318322
ProductCategory: 'Accessories', 'All cities': 'All Cities',
319323
ProductCategory_level: 1, 'All cities_level': 0,
320-
'USA-UnitsSold': 293, 'USA-AmountOfSale': 25074.94
324+
'UK-UnitsSold': 293, 'UK-AmountOfSale': 25074.94
321325
}, {
322326
ProductCategory: 'Components', 'All cities': 'All Cities',
323327
ProductCategory_level: 1, 'All cities_level': 0,
324-
'USA-UnitsSold': 240, 'USA-AmountOfSale': 4351.2
328+
'Japan-UnitsSold': 240, 'Japan-AmountOfSale': 4351.2,
329+
'Bulgaria-UnitsSold': 492, 'Bulgaria-AmountOfSale': 7896.6
325330
}
326331
];
327332
expect(pivotGrid.selectedRows).toEqual(expected);

projects/igniteui-angular/src/lib/test-utils/pivot-grid-samples.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ export class IgxPivotGridTestBaseComponent {
109109
export class IgxPivotGridTestComplexHierarchyComponent extends IgxPivotGridTestBaseComponent {
110110
constructor() {
111111
super();
112+
this.data = [
113+
{
114+
ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley Brooker',
115+
Country: 'Bulgaria', City: 'Plovdiv', Date: '01/01/2012', UnitsSold: 282
116+
},
117+
{
118+
ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa Longbottom',
119+
Country: 'US', City: 'New York', Date: '01/05/2013', UnitsSold: 296
120+
},
121+
{
122+
ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia Burson',
123+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '01/06/2011', UnitsSold: 68
124+
},
125+
{
126+
ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David Haley',
127+
Country: 'UK', City: 'London', Date: '04/07/2012', UnitsSold: 293
128+
},
129+
{
130+
ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John Smith',
131+
Country: 'Japan', City: 'Yokohama', Date: '12/08/2012', UnitsSold: 240
132+
},
133+
{
134+
ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry Lieb',
135+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '05/12/2011', UnitsSold: 456
136+
},
137+
{
138+
ProductCategory: 'Components', UnitPrice: 16.05, SellerName: 'Walter Pang',
139+
Country: 'Bulgaria', City: 'Sofia', Date: '02/19/2013', UnitsSold: 492
140+
}];
112141
this.pivotConfigHierarchy = {
113142
columns: [
114143

0 commit comments

Comments
 (0)