Skip to content

Commit baf7303

Browse files
authored
Merge pull request #10399 from IgniteUI/mdragnev/row-dimensions
Introduce additional memberFunction to pivot dimensions and rename member to memberName
2 parents 8a7bbb7 + 178aa56 commit baf7303

File tree

10 files changed

+1018
-635
lines changed

10 files changed

+1018
-635
lines changed

projects/igniteui-angular/src/lib/data-operations/pivot-strategy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,21 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
4646
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);
4747
// generate flat data from the hierarchies
4848
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
49-
row.fieldName = hierarchies.get(hierarchies.keys().next().value).dimension.fieldName;
5049
prevRowDims.push(row);
5150
prevDim = row;
5251
} else {
5352
const newData = [...data];
5453
for (let i = 0; i < newData.length; i++) {
55-
const currData = newData[i][prevDim.fieldName + '_' + pivotKeys.records];
54+
const currData = newData[i][prevDim.memberName + '_' + pivotKeys.records];
5655
const hierarchyFields = PivotUtil
5756
.getFieldsHierarchy(currData, [row], PivotDimensionType.Row, pivotKeys);
5857
const siblingData = PivotUtil
5958
.processHierarchy(hierarchyFields, newData[i] ?? [], pivotKeys, 0);
60-
row.fieldName = hierarchyFields.get(hierarchyFields.keys().next().value).dimension.fieldName;
6159
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
6260

6361
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
6462
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row)) {
65-
newData[i][row.fieldName + '_' + pivotKeys.records] = siblingData;
63+
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
6664
} else {
6765
newData.splice(i , 1, ...siblingData);
6866
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { GridType } from '../common/grid.interface';
1919
import { IgxGridNavigationService } from '../grid-navigation.service';
2020
import { IgxGridCRUDService } from '../common/crud.service';
2121
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
22-
import { IPivotConfiguration, IPivotDimension, IPivotKeys, PivotDimensionType } from './pivot-grid.interface';
22+
import { IPivotConfiguration, IPivotKeys, PivotDimensionType } from './pivot-grid.interface';
2323
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
2424
import { IgxColumnGroupComponent } from '../columns/column-group.component';
2525
import { IgxColumnComponent } from '../columns/column.component';
@@ -282,7 +282,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
282282
let fieldsMap;
283283
if (this.pivotConfiguration.columnStrategy && this.pivotConfiguration.columnStrategy instanceof NoopPivotDimensionsStrategy) {
284284
const fields = this.generateDataFields(data);
285-
const rowFields = PivotUtil.flatten(this.pivotConfiguration.rows).map(x => x.fieldName);
285+
const rowFields = PivotUtil.flatten(this.pivotConfiguration.rows).map(x => x.memberName);
286286
const keyFields = Object.values(this.pivotKeys);
287287
const filteredFields = fields.filter(x => rowFields.indexOf(x) === -1 && keyFields.indexOf(x) === -1 &&
288288
x.indexOf('_level') === -1 && x.indexOf('_records') === -1);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export interface IPivotConfiguration {
1919
export interface IPivotDimension {
2020
// allow defining a hierarchy when multiple sub groups need to be extracted from single member.
2121
childLevel?: IPivotDimension;
22-
// field name which to use to extract value or function that extract the value.
23-
member: string | ((data: any) => any);
22+
// field name which to use to extract value
23+
memberName: string;
24+
// function that extract the value
25+
memberFunction?: (data: any) => any;
2426
// Enables/Disables a particular dimension from pivot structure.
2527
enabled: boolean;
26-
// additional field name when using member as a function
27-
fieldName?: string;
2828
}
2929

3030
export interface IPivotValue {

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

Lines changed: 748 additions & 342 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, ViewChild } from '@angular/core';
21
import { fakeAsync, TestBed } from '@angular/core/testing';
32
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { IgxNumberSummaryOperand, IgxPivotGridComponent, IgxPivotGridModule, IPivotConfiguration } from 'igniteui-angular';
3+
import { IgxPivotGridModule } from 'igniteui-angular';
54
import { configureTestSuite } from '../../test-utils/configure-suite';
5+
import { IgxPivotGridTestBaseComponent } from '../../test-utils/pivot-grid-samples.spec';
66

77
describe('Basic IgxPivotGrid #pivotGrid', () => {
88
let fixture;
@@ -38,95 +38,3 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
3838
expect(cells.last.nativeElement.classList).not.toContain('test');
3939
});
4040
});
41-
42-
43-
@Component({
44-
template: `
45-
<igx-pivot-grid #grid [data]="data" [pivotConfiguration]="pivotConfigHierarchy">
46-
</igx-pivot-grid>`
47-
})
48-
export class IgxPivotGridTestBaseComponent {
49-
@ViewChild('grid', { read: IgxPivotGridComponent, static: true }) public pivotGrid: IgxPivotGridComponent;
50-
public data;
51-
52-
53-
public cellClasses;
54-
55-
56-
public pivotConfigHierarchy: IPivotConfiguration;
57-
58-
constructor() {
59-
this.data = [
60-
{
61-
ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley',
62-
Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282
63-
},
64-
{
65-
ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa',
66-
Country: 'USA', Date: '01/05/2019', UnitsSold: 296
67-
},
68-
{
69-
ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia',
70-
Country: 'Uruguay', Date: '01/06/2020', UnitsSold: 68
71-
},
72-
{
73-
ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David',
74-
Country: 'USA', Date: '04/07/2021', UnitsSold: 293
75-
},
76-
{
77-
ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John',
78-
Country: 'USA', Date: '12/08/2021', UnitsSold: 240
79-
},
80-
{
81-
ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry',
82-
Country: 'Uruguay', Date: '05/12/2020', UnitsSold: 456
83-
},
84-
{
85-
ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter',
86-
Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492
87-
}];
88-
89-
this.cellClasses = {
90-
test: this.callback,
91-
test2: this.callback1
92-
};
93-
94-
this.pivotConfigHierarchy = {
95-
columns: [{
96-
member: 'Country',
97-
enabled: true
98-
},
99-
],
100-
rows: [{
101-
member: () => 'All',
102-
enabled: true,
103-
childLevel: {
104-
fieldName: 'ProductCategory',
105-
member: (data) => data.ProductCategory,
106-
enabled: true
107-
}
108-
}],
109-
values: [
110-
{
111-
member: 'UnitsSold',
112-
aggregate: IgxNumberSummaryOperand.sum,
113-
enabled: true,
114-
// dataType: 'currency',
115-
formatter: (value) => value ? value + '$' : undefined,
116-
styles: this.cellClasses
117-
},
118-
{
119-
member: 'UnitPrice',
120-
aggregate: IgxNumberSummaryOperand.sum,
121-
enabled: true,
122-
dataType: 'currency'
123-
}
124-
],
125-
filters: null
126-
};
127-
}
128-
129-
public callback = (rowData: any, columnKey: any) => rowData[columnKey] >= 5;
130-
public callback1 = (rowData: any, columnKey: any) => rowData[columnKey] < 5;
131-
132-
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,8 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
112112
}
113113

114114
protected extractFromDimension(dim: IPivotDimension, index: number = 0, lvl = 0) {
115-
const field = PivotUtil.resolveFieldName(dim, this.rowData);
116-
let header = null;
117-
if (typeof dim.member === 'string') {
118-
header = this.rowData[dim.member];
119-
} else if (typeof dim.member === 'function' && dim.fieldName) {
120-
header = this.rowData[dim.fieldName];
121-
} else {
122-
header = dim.member.call(this, this.rowData);
123-
}
115+
const field = dim.memberName;
116+
const header = this.rowData[field];
124117
const col = this._createColComponent(field, header, index, dim, lvl);
125118
return col;
126119
}

0 commit comments

Comments
 (0)