Skip to content

Commit e48ef56

Browse files
authored
Merge pull request #4818 from VisActor/4815-bug-pivotTable-tree-subTotal
4815 bug pivot table tree sub total
2 parents c2130c9 + dd2b271 commit e48ef56

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: when pivot table set grid-tree subTotal value not show #4815\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "892739385@qq.com"
11+
}

packages/vtable/src/dataset/dataset.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,20 @@ export class Dataset {
11451145
indicatorPosition?: { position: 'col' | 'row'; index?: number }
11461146
): IAggregator {
11471147
const indicatorIndex = this.indicatorKeys.indexOf(indicator);
1148+
//#region 获取行和列的维度key,考虑到tree模式被折叠的情况 rowKey colKey会小于rows和columns的长度
1149+
let rowDimensionKey;
1150+
if (indicatorPosition?.position === 'row') {
1151+
rowDimensionKey = rowKey.length >= 2 ? this.rows[rowKey.length - 2] : undefined;
1152+
} else {
1153+
rowDimensionKey = this.rows[rowKey.length - 1];
1154+
}
1155+
let colDimensionKey;
1156+
if (indicatorPosition?.position === 'col') {
1157+
colDimensionKey = colKey.length >= 2 ? this.columns[colKey.length - 2] : undefined;
1158+
} else {
1159+
colDimensionKey = this.columns[colKey.length - 1];
1160+
}
1161+
//#endregion
11481162
// let agg;
11491163
let flatRowKey;
11501164
let flatColKey;
@@ -1165,7 +1179,8 @@ export class Dataset {
11651179
} else if (
11661180
this.totals?.row?.subTotalsDimensions &&
11671181
this.totals?.row?.subTotalsDimensions?.length >= 1 &&
1168-
rowKey[rowKey.length - 1] !== this.rowSubTotalLabel
1182+
rowKey[rowKey.length - 1] !== this.rowSubTotalLabel &&
1183+
this.totals.row.subTotalsDimensions.find(dimension => dimension === rowDimensionKey) //如果维度key在subTotalsDimensions中 则需要补充小计标签名到rowKey中
11691184
) {
11701185
rowKey.push(this.rowSubTotalLabel);
11711186
}
@@ -1190,7 +1205,8 @@ export class Dataset {
11901205
} else if (
11911206
this.totals?.column?.subTotalsDimensions &&
11921207
this.totals?.column?.subTotalsDimensions?.length >= 1 &&
1193-
colKey[colKey.length - 1] !== this.colSubTotalLabel
1208+
colKey[colKey.length - 1] !== this.colSubTotalLabel &&
1209+
this.totals.column.subTotalsDimensions.find(dimension => dimension === colDimensionKey) //如果维度key在subTotalsDimensions中 则需要补充小计标签名到colKey中
11941210
) {
11951211
colKey.push(this.colSubTotalLabel);
11961212
}

0 commit comments

Comments
 (0)