Skip to content

Commit

Permalink
feat: support calculate field for PivotTable #1941
Browse files Browse the repository at this point in the history
  • Loading branch information
fangsmile committed Jun 19, 2024
1 parent 326e215 commit 8dc02e6
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/vtable/src/data/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ export class DataSource extends EventTarget implements DataSourceAPI {
// 注册聚合类型
registedAggregators: {
[key: string]: {
new (dimension: string | string[], formatFun?: any, isRecord?: boolean, aggregationFun?: Function): Aggregator;
new (config: {
dimension: string | string[];
formatFun?: any;
isRecord?: boolean;
aggregationFun?: Function;
}): Aggregator;
};
} = {};
rowHierarchyType: 'grid' | 'tree';
Expand Down Expand Up @@ -279,25 +284,25 @@ export class DataSource extends EventTarget implements DataSourceAPI {
if (Array.isArray(aggragation)) {
for (let j = 0; j < aggragation.length; j++) {
const item = aggragation[j];
const aggregator = new this.registedAggregators[item.aggregationType](
field as string,
item.formatFun,
true,
(item as CustomAggregation).aggregationFun
);
const aggregator = new this.registedAggregators[item.aggregationType]({
dimension: field as string,
formatFun: item.formatFun,
isRecord: true,
aggregationFun: (item as CustomAggregation).aggregationFun
});
this.fieldAggregators.push(aggregator);
if (!columnObjs[i].aggregator) {
columnObjs[i].aggregator = [];
}
columnObjs[i].aggregator.push(aggregator);
}
} else {
const aggregator = new this.registedAggregators[aggragation.aggregationType](
field as string,
aggragation.formatFun,
true,
(aggragation as CustomAggregation).aggregationFun
);
const aggregator = new this.registedAggregators[aggragation.aggregationType]({
dimension: field as string,
formatFun: aggragation.formatFun,
isRecord: true,
aggregationFun: (aggragation as CustomAggregation).aggregationFun
});
this.fieldAggregators.push(aggregator);
columnObjs[i].aggregator = aggregator;
}
Expand Down

0 comments on commit 8dc02e6

Please sign in to comment.