Skip to content

Commit c4c8d91

Browse files
MKirovaMKirova
authored andcommitted
Allow setting a custom aggregateList to show in chip drop down.
1 parent 79dd48a commit c4c8d91

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export interface IPivotValue {
4444
* use predefined ones from IgxPivotAggregate and its variants
4545
*/
4646
aggregate: PivotAggregation;
47+
/**
48+
* List of aggregates to show in aggregate drop-down.
49+
*/
50+
aggregateList?: IPivotAggregator[];
4751
// Enables/Disables a particular value from pivot aggregation.
4852
enabled: boolean;
4953
// Allow conditionally styling of the IgxPivotGrid cells

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface IgxGridRowSelectorsTemplateContext {
4242
selector: 'igx-pivot-header-row',
4343
templateUrl: './pivot-header-row.component.html'
4444
})
45-
export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implements OnInit {
45+
export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
4646

4747
@Input()
4848
public row: IgxPivotRowComponent;
@@ -73,10 +73,10 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
7373
super(ref, cdr);
7474
}
7575

76-
public ngOnInit() {
77-
this.valueData = new Map();
78-
const values = this.grid.pivotConfiguration.values;
79-
values.forEach(val => {
76+
public getAggregateList(val: IPivotValue): IPivotAggregator[] {
77+
if (val.aggregateList) {
78+
return val.aggregateList;
79+
}
8080
let defaultAggr = this.getAggregatorsForValue(val);
8181
const isDefault = defaultAggr.find(x => x.aggregator.name === val.aggregate.name);
8282
// resolve custom aggregations
@@ -97,9 +97,8 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
9797
aggregator: val.aggregate
9898
}];
9999
}
100-
this.valueData.set(val.member, defaultAggr);
101-
});
102-
}
100+
return defaultAggr;
101+
}
103102

104103
public rowRemoved(event: IBaseChipEventArgs) {
105104
const row = this.grid.pivotConfiguration.rows.find(x => x.memberName === event.owner.id);
@@ -147,7 +146,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
147146
}
148147

149148
public isSelected(val: IPivotAggregator) {
150-
return this.value.aggregate.name === val.aggregator.name;
149+
return this.value.aggregate === val.aggregator;
151150
}
152151

153152
public onDimDragOver(event, dimension?: PivotDimensionType) {
@@ -320,7 +319,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
320319

321320
protected updateDropDown(value: IPivotValue, dropdown) {
322321
this.value = value;
323-
this.aggregateList = this.valueData.get(value.member);
322+
this.aggregateList = this.getAggregateList(value);
324323
dropdown.open(this._subMenuOverlaySettings);
325324
}
326325
}

src/app/pivot-grid/pivot-grid.sample.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ import { HIERARCHICAL_SAMPLE_DATA } from '../shared/sample-data';
1010
export class IgxTotalSaleAggregate {
1111
public static totalSale: PivotAggregation = (members, data: any) =>
1212
data.reduce((accumulator, value) => accumulator + value.UnitPrice * value.UnitsSold, 0);
13+
14+
public static totalMin: PivotAggregation = (members, data: any) => {
15+
let min = 0;
16+
if (data.length === 1) {
17+
min = data[0].UnitPrice * data[0].UnitsSold;
18+
} else if (data.length > 1) {
19+
min = data.reduce((a, b) => Math.min(a.UnitPrice * a.UnitsSold, b.UnitPrice * b.UnitsSold));
20+
}
21+
return min;
22+
};
23+
24+
public static totalMax: PivotAggregation = (members, data: any) => {
25+
let max = 0;
26+
if (data.length === 1) {
27+
max = data[0].UnitPrice * data[0].UnitsSold;
28+
} else if (data.length > 1) {
29+
max = data.reduce((a, b) => Math.max(a.UnitPrice * a.UnitsSold, b.UnitPrice * b.UnitsSold));
30+
}
31+
return max;
32+
};
1333
}
1434

1535
@Component({
@@ -75,6 +95,19 @@ export class PivotGridSampleComponent {
7595
member: 'AmountOfSale',
7696
displayName: 'Amount of Sale',
7797
aggregate: IgxTotalSaleAggregate.totalSale,
98+
aggregateList: [{
99+
key: 'sum',
100+
aggregator: IgxTotalSaleAggregate.totalSale,
101+
label: 'Sum Sale'
102+
},{
103+
key: 'min',
104+
aggregator: IgxTotalSaleAggregate.totalMin,
105+
label: 'Min Sale'
106+
},{
107+
key: 'max',
108+
aggregator: IgxTotalSaleAggregate.totalMax,
109+
label: 'Max Sale'
110+
}],
78111
enabled: true,
79112
dataType: 'currency',
80113
styles: {

0 commit comments

Comments
 (0)