Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
IPivotValue,
PivotDimensionType
} from "./pivot-grid.interface";
import { PivotUtil } from './pivot-util';

interface IDataSelectorPanel {
name: string;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
43 changes: 41 additions & 2 deletions projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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();
}
}
}