diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts index f78b38ce452..5cca4c3de72 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts @@ -37,6 +37,7 @@ import { IPivotValue, PivotDimensionType } from "./pivot-grid.interface"; +import { PivotUtil } from './pivot-util'; interface IDataSelectorPanel { name: string; @@ -365,7 +366,7 @@ export class IgxPivotDataSelectorComponent { ) { this.value = value; dropdown.width = "200px"; - this.aggregateList = this.getAggregateList(value); + this.aggregateList = PivotUtil.getAggregateList(value, this.grid); dropdown.open(this._subMenuOverlaySettings); } @@ -392,53 +393,6 @@ export class IgxPivotDataSelectorComponent { } } - /** - * @hidden - * @internal - */ - protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] { - const dataType = - value.dataType || - this.grid.resolveDataTypes(this.grid.data[0][value.member]); - switch (dataType) { - case GridColumnDataType.Number: - case GridColumnDataType.Currency: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Date: - case GridColumnDataType.DateTime: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Time: - return IgxPivotTimeAggregate.aggregators(); - default: - return IgxPivotAggregate.aggregators(); - } - } - - /** - * @hidden - * @internal - */ - public getAggregateList(val: IPivotValue): IPivotAggregator[] { - if (!val.aggregateList) { - let defaultAggr = this.getAggregatorsForValue(val); - const isDefault = defaultAggr.find( - (x) => x.key === val.aggregate.key - ); - // resolve custom aggregations - if (!isDefault && this.grid.data[0][val.member] !== undefined) { - // if field exists, then we can apply default aggregations and add the custom one. - defaultAggr.unshift(val.aggregate); - } else if (!isDefault) { - // otherwise this is a custom aggregation that is not compatible - // with the defaults, since it operates on field that is not in the data - // leave only the custom one. - defaultAggr = [val.aggregate]; - } - val.aggregateList = defaultAggr; - } - return val.aggregateList; - } - /** * @hidden * @internal diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts index 5ed7b228b8c..df90929d648 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts @@ -277,29 +277,6 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem return chips && chips.length > 0 ? chips.first.nativeElement.clientHeight : 0; } - /** - * @hidden - * @internal - */ - public getAggregateList(val: IPivotValue): IPivotAggregator[] { - if (!val.aggregateList) { - let defaultAggr = this.getAggregatorsForValue(val); - const isDefault = defaultAggr.find(x => x.key === val.aggregate.key); - // resolve custom aggregations - if (!isDefault && this.grid.data[0][val.member] !== undefined) { - // if field exists, then we can apply default aggregations and add the custom one. - defaultAggr.unshift(val.aggregate); - } else if (!isDefault) { - // otherwise this is a custom aggregation that is not compatible - // with the defaults, since it operates on field that is not in the data - // leave only the custom one. - defaultAggr = [val.aggregate]; - } - val.aggregateList = defaultAggr; - } - return val.aggregateList; - } - /** * @hidden * @internal @@ -592,26 +569,10 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem return isColumn ? PivotDimensionType.Column : isRow ? PivotDimensionType.Row : PivotDimensionType.Filter; } - protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] { - const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]); - switch (dataType) { - case GridColumnDataType.Number: - case GridColumnDataType.Currency: - return IgxPivotNumericAggregate.aggregators(); - case GridColumnDataType.Date: - case GridColumnDataType.DateTime: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Time: - return IgxPivotTimeAggregate.aggregators(); - default: - return IgxPivotAggregate.aggregators(); - } - } - protected updateDropDown(value: IPivotValue, dropdown: IgxDropDownComponent, chip: IgxChipComponent) { this.value = value; dropdown.width = chip.nativeElement.clientWidth + 'px'; - this.aggregateList = this.getAggregateList(value); + this.aggregateList = PivotUtil.getAggregateList(value, this.grid); dropdown.open(this._subMenuOverlaySettings); } } diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts index a0544903009..e95155ff85e 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts @@ -1,10 +1,12 @@ import { cloneValue } from '../../core/utils'; -import { DataUtil } from '../../data-operations/data-util'; +import { DataUtil, GridColumnDataType } from '../../data-operations/data-util'; import { FilteringLogic } from '../../data-operations/filtering-expression.interface'; import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree'; import { ISortingExpression } from '../../data-operations/sorting-strategy'; +import { PivotGridType } from '../common/grid.interface'; import { IGridSortingStrategy, IgxSorting } from '../common/strategy'; -import { IPivotConfiguration, IPivotDimension, IPivotGridRecord, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface'; +import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate'; +import { IPivotAggregator, IPivotConfiguration, IPivotDimension, IPivotGridRecord, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface'; export class PivotUtil { @@ -399,4 +401,41 @@ export class PivotUtil { } } } + + public static getAggregateList(val: IPivotValue, grid: PivotGridType): IPivotAggregator[] { + if (!val.aggregateList) { + let defaultAggr = this.getAggregatorsForValue(val, grid); + const isDefault = defaultAggr.find( + (x) => x.key === val.aggregate.key + ); + // resolve custom aggregations + if (!isDefault && grid.data[0][val.member] !== undefined) { + // if field exists, then we can apply default aggregations and add the custom one. + defaultAggr.unshift(val.aggregate); + } else if (!isDefault) { + // otherwise this is a custom aggregation that is not compatible + // with the defaults, since it operates on field that is not in the data + // leave only the custom one. + defaultAggr = [val.aggregate]; + } + val.aggregateList = defaultAggr; + } + return val.aggregateList; + } + + public static getAggregatorsForValue(value: IPivotValue, grid: PivotGridType): IPivotAggregator[] { + const dataType = value.dataType || grid.resolveDataTypes(grid.data[0][value.member]); + switch (dataType) { + case GridColumnDataType.Number: + case GridColumnDataType.Currency: + return IgxPivotNumericAggregate.aggregators(); + case GridColumnDataType.Date: + case GridColumnDataType.DateTime: + return IgxPivotDateAggregate.aggregators(); + case GridColumnDataType.Time: + return IgxPivotTimeAggregate.aggregators(); + default: + return IgxPivotAggregate.aggregators(); + } + } }