我需要显示组行中组中的第一个值,所以首先我尝试使用聚合显示常量,我有这个列def
name: 'Stack',
displayName: 'Stack',
grouping: { groupPriority: 1 },
treeAggregation: { type:this.uiGridGroupingConstants.aggregation.CUSTOM },
customTreeAggregationFn: this.aggregateService.accumulateNumValue,
customTreeAggregationFinalizerFn: this.aggregateService.medianFinalize,
visible: true,
minWidth: '70',
使用另一个隐藏的列完成分组,我尝试使用自定义aggregationTree和finalize方法仅执行
if ( angular.isUndefined(aggregation.stats.accumulator) ){
aggregation.stats.accumulator = [];
}
这段代码抛出错误
TypeError: Cannot read property 'accumulator' of undefined
at GridColumn.AggregationService.medianFinalize [as customTreeAggregationFinalizerFn] (http://localhost:8080/bundle.js:135388:55)
at Object.finaliseAggregation (http://localhost:8080/bundle.js:74042:28)
at http://localhost:8080/bundle.js:74073:20
at Array.forEach (native)
at Object.finaliseAggregations (http://localhost:8080/bundle.js:74072:36)
at createNode (http://localhost:8080/bundle.js:73647:24)
at Array.forEach (native)
at Object.createTree (http://localhost:8080/bundle.js:73679:25)
at Grid.treeRows (http://localhost:8080/bundle.js:73544:39)
at startProcessor (http://localhost:8080/bundle.js:52026:34)
我不明白这是怎么抛出错误的,我删除了3行代码并且错误不再存在但我显然需要访问tats.accumulator,因为这是我在聚合中推送数据的数组功能
答案 0 :(得分:1)
你试过了吗?
if ( angular.isUndefined(aggregation.stats) ){
aggregation.stats={accumulator : []};
}
答案 1 :(得分:0)
我能够解决问题是聚合函数而不是终结函数的问题,在我的聚合服务中我有这个函数
public accumulateNumValue (aggregation, fieldValue, value) {
if (angular.isUndefined(aggregation.stats) ){
aggregation.stats = {sum: 0};
}
if ( angular.isUndefined(aggregation.stats.accumulator) ){
aggregation.stats.accumulator = [];
}
aggregation.stats.accumulator.push(value);
}
我正在推动值而不是fieldValue,我刚刚开始推动字段值,累积功能现在正常工作。
public accumulateNumValue (aggregation, fieldValue, value) {
if (angular.isUndefined(aggregation.stats) ){
aggregation.stats = {sum: 0};
}
if ( angular.isUndefined(aggregation.stats.accumulator) ){
aggregation.stats.accumulator = [];
}
aggregation.stats.accumulator.push(fieldValue);
}
并显示组中的第一个元素,你需要在终结器函数中分配" aggregation.rendered"到数组的第一个元素
public medianFinalize(aggregation) {
if (angular.isUndefined(aggregation.stats) ) {
aggregation.stats={accumulator : []};
}
if(aggregation.stats.accumulator.length >0) {
aggregation.rendered = aggregation.stats.accumulator[0];
}
}