fix: when call updateColumns should update aggregation #2519

This commit is contained in:
fangsmile 2024-10-08 17:24:07 +08:00 committed by Rui-Sun
parent 4f12853fc6
commit 872842ac65
3 changed files with 25 additions and 1 deletions

View File

@ -19,7 +19,12 @@ import type {
import { HierarchyState } from './ts-types';
import { SimpleHeaderLayoutMap } from './layout';
import { isArray, isValid } from '@visactor/vutils';
import { _setDataSource, _setRecords, generateAggregationForColumn } from './core/tableHelper';
import {
_setDataSource,
_setRecords,
checkHasAggregationOnColumnDefine,
generateAggregationForColumn
} from './core/tableHelper';
import { BaseTable } from './core';
import type { BaseTableAPI, ListTableProtected } from './ts-types/base-table';
import { TABLE_EVENT_TYPE } from './core/TABLE_EVENT_TYPE';
@ -224,6 +229,10 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.internalProps.headerHelper.setTableColumnsEditor();
this._hasAutoImageColumn = undefined;
this.refreshHeader();
this.dataSource.updateColumns?.(this.internalProps.columns);
if (this.records && checkHasAggregationOnColumnDefine(columns)) {
this.dataSource.processRecords(this.dataSource.dataSourceObj?.records ?? this.dataSource.dataSourceObj);
}
this.internalProps.useOneRowHeightFillAll = false;
this.scenegraph.clearCells();
this.headerStyleCache = new Map();

View File

@ -7,6 +7,7 @@ import { Rect } from '../tools/Rect';
import * as calc from '../tools/calc';
import type {
Aggregation,
ColumnsDefine,
CustomAggregation,
FullExtendStyle,
ListTableAPI,
@ -472,3 +473,13 @@ export function generateAggregationForColumn(table: ListTable) {
}
}
}
export function checkHasAggregationOnColumnDefine(colDefs: ColumnsDefine) {
for (let i = 0; i < colDefs.length; i++) {
const colDef = colDefs[i];
if (colDef.aggregation) {
return true;
}
}
return false;
}

View File

@ -275,8 +275,12 @@ export class DataSource extends EventTarget implements DataSourceAPI {
this.registerAggregator(AggregationType.NONE, NoneAggregator);
this.registerAggregator(AggregationType.CUSTOM, CustomAggregator);
}
updateColumns(columns: ColumnsDefine) {
this.columns = columns;
}
_generateFieldAggragations() {
const columnObjs = this.columns;
this.fieldAggregators = [];
for (let i = 0; i < columnObjs?.length; i++) {
delete (columnObjs[i] as any).vtable_aggregator; //重置聚合器 如更新了过滤条件都需要重新计算
const field = columnObjs[i].field;