Skip to content

Commit 5b3be7f

Browse files
MKirovaMKirova
authored andcommitted
Cache default aggregate list, together with custom aggregate that is not in list.
1 parent bf6487a commit 5b3be7f

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { IBaseChipEventArgs, IgxChipComponent } from '../../chips/chip.component
1111
import { GridColumnDataType } from '../../data-operations/data-util';
1212
import { ISelectionEventArgs } from '../../drop-down/drop-down.common';
1313
import { IgxDropDownComponent } from '../../drop-down/drop-down.component';
14-
import { AbsoluteScrollStrategy, AutoPositionStrategy, OverlaySettings,
15-
PositionSettings, VerticalAlignment } from '../../services/public_api';
14+
import {
15+
AbsoluteScrollStrategy, AutoPositionStrategy, OverlaySettings,
16+
PositionSettings, VerticalAlignment
17+
} from '../../services/public_api';
1618
import { IgxGridHeaderRowComponent } from '../headers/grid-header-row.component';
1719
import { DropPosition } from '../moving/moving.service';
1820
import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate';
@@ -68,14 +70,12 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
6870
protected ref: ElementRef<HTMLElement>,
6971
protected cdr: ChangeDetectorRef,
7072
protected renderer: Renderer2,
71-
) {
72-
super(ref, cdr);
73+
) {
74+
super(ref, cdr);
7375
}
7476

7577
public getAggregateList(val: IPivotValue): IPivotAggregator[] {
76-
if (val.aggregateList) {
77-
return val.aggregateList;
78-
}
78+
if (!val.aggregateList) {
7979
let defaultAggr = this.getAggregatorsForValue(val);
8080
const isDefault = defaultAggr.find(x => x.key === val.aggregate.key);
8181
// resolve custom aggregations
@@ -88,8 +88,10 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
8888
// leave only the custom one.
8989
defaultAggr = [val.aggregate];
9090
}
91-
return defaultAggr;
91+
val.aggregateList = defaultAggr;
9292
}
93+
return val.aggregateList;
94+
}
9395

9496
public rowRemoved(event: IBaseChipEventArgs) {
9597
const row = this.grid.pivotConfiguration.rows.find(x => x.memberName === event.owner.id);
@@ -124,7 +126,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
124126
// close for previous chip
125127
dropdown.close();
126128
dropdown.closed.pipe(first()).subscribe(() => {
127-
this.updateDropDown(value, dropdown, chip);
129+
this.updateDropDown(value, dropdown, chip);
128130
});
129131
}
130132
}
@@ -142,7 +144,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
142144

143145
public onDimDragOver(event, dimension?: PivotDimensionType) {
144146
const typeMismatch = dimension !== undefined ? this.grid.pivotConfiguration.values.find(x => x.member === event.dragChip.id) :
145-
!this.grid.pivotConfiguration.values.find(x => x.member === event.dragChip.id);
147+
!this.grid.pivotConfiguration.values.find(x => x.member === event.dragChip.id);
146148
if (typeMismatch) {
147149
// cannot drag between dimensions and value
148150
return;
@@ -152,7 +154,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
152154
const clientRect = event.owner.nativeElement.getBoundingClientRect();
153155
const pos = clientRect.width / 2;
154156

155-
this._dropPos = event.originalEvent.offsetX > pos ? DropPosition.AfterDropTarget : DropPosition.BeforeDropTarget;
157+
this._dropPos = event.originalEvent.offsetX > pos ? DropPosition.AfterDropTarget : DropPosition.BeforeDropTarget;
156158
if (this._dropPos === DropPosition.AfterDropTarget) {
157159
event.owner.nativeElement.style.borderRight = '1px solid red';
158160
event.owner.nativeElement.style.borderLeft = '';
@@ -177,7 +179,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
177179
public onAreaDragEnter(event, area, dimension?: PivotDimensionType) {
178180
const dragId = event.detail.owner.element.nativeElement.parentElement.id;
179181
const typeMismatch = dimension !== undefined ? this.grid.pivotConfiguration.values.find(x => x.member === dragId) :
180-
!this.grid.pivotConfiguration.values.find(x => x.member === dragId);
182+
!this.grid.pivotConfiguration.values.find(x => x.member === dragId);
181183
if (typeMismatch) {
182184
// cannot drag between dimensions and value
183185
return;
@@ -223,12 +225,12 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
223225
const isNewChip = chip === undefined;
224226
//const chipIndex = chipsArray.indexOf(event.owner) !== -1 ? chipsArray.indexOf(event.owner) : chipsArray.length;
225227
const chipIndex = currentDim.findIndex(x => x.memberName === event.owner.id) !== -1 ?
226-
currentDim.findIndex(x => x.memberName === event.owner.id) : currentDim.length;
228+
currentDim.findIndex(x => x.memberName === event.owner.id) : currentDim.length;
227229
const targetIndex = this._dropPos === DropPosition.AfterDropTarget ? chipIndex + 1 : chipIndex;
228230
if (isNewChip) {
229231
const allDims = this.grid.pivotConfiguration.rows
230-
.concat(this.grid.pivotConfiguration.columns)
231-
.concat(this.grid.pivotConfiguration.filters);
232+
.concat(this.grid.pivotConfiguration.columns)
233+
.concat(this.grid.pivotConfiguration.filters);
232234
// chip moved from external collection
233235
const dims = allDims.filter(x => x && x.memberName === dragId);
234236
if (dims.length === 0) {
@@ -278,10 +280,10 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
278280
}
279281
return this.grid.pivotConfiguration.rows;
280282
case PivotDimensionType.Column:
281-
if (!this.grid.pivotConfiguration.columns) {
282-
this.grid.pivotConfiguration.columns = [];
283-
}
284-
return this.grid.pivotConfiguration.columns;
283+
if (!this.grid.pivotConfiguration.columns) {
284+
this.grid.pivotConfiguration.columns = [];
285+
}
286+
return this.grid.pivotConfiguration.columns;
285287
case PivotDimensionType.Filter:
286288
if (!this.grid.pivotConfiguration.filters) {
287289
this.grid.pivotConfiguration.filters = [];
@@ -293,19 +295,19 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
293295
}
294296

295297
protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] {
296-
const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]);
297-
switch (dataType) {
298+
const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]);
299+
switch (dataType) {
298300
case GridColumnDataType.Number:
299301
case GridColumnDataType.Currency:
300-
return IgxPivotNumericAggregate.aggregators();
302+
return IgxPivotNumericAggregate.aggregators();
301303
case GridColumnDataType.Date:
302304
case GridColumnDataType.DateTime:
303-
return IgxPivotDateAggregate.aggregators();
305+
return IgxPivotDateAggregate.aggregators();
304306
case GridColumnDataType.Time:
305307
return IgxPivotTimeAggregate.aggregators();
306-
default:
308+
default:
307309
return IgxPivotAggregate.aggregators();
308-
}
310+
}
309311
}
310312

311313
protected updateDropDown(value: IPivotValue, dropdown: IgxDropDownComponent, chip: IgxChipComponent) {

0 commit comments

Comments
 (0)