From d860a18bd1041e9f63bc7937270b11981f9358b0 Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Sat, 29 Jun 2024 21:35:22 +0800 Subject: [PATCH] fix: pivotTable virtual node edit value not work #2002 --- packages/vtable/src/PivotTable.ts | 240 ++++++++++++++++++------------ 1 file changed, 144 insertions(+), 96 deletions(-) diff --git a/packages/vtable/src/PivotTable.ts b/packages/vtable/src/PivotTable.ts index 2e47ffbcc..8b1345de3 100644 --- a/packages/vtable/src/PivotTable.ts +++ b/packages/vtable/src/PivotTable.ts @@ -572,24 +572,32 @@ export class PivotTable extends BaseTable implements PivotTableAPI { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); if (cellDimensionPath) { let indicatorPosition: { position: 'col' | 'row'; index?: number }; - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => { - if (colPath.indicatorKey) { - indicatorPosition = { - position: 'col', - index - }; - } - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => { - if (rowPath.indicatorKey) { - indicatorPosition = { - position: 'row', - index - }; - } - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any, index: number) => { + if (colPath.indicatorKey) { + indicatorPosition = { + position: 'col', + index + }; + } + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any, index: number) => { + if (rowPath.indicatorKey) { + indicatorPosition = { + position: 'row', + index + }; + } + return rowPath.indicatorKey ?? rowPath.value; + }); const aggregator = this.dataset.getAggregator( // !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, // this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys, @@ -736,24 +744,32 @@ export class PivotTable extends BaseTable implements PivotTableAPI { } else if (this.dataset) { let indicatorPosition: { position: 'col' | 'row'; index?: number }; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => { - if (colPath.indicatorKey) { - indicatorPosition = { - position: 'col', - index - }; - } - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => { - if (rowPath.indicatorKey) { - indicatorPosition = { - position: 'row', - index - }; - } - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any, index: number) => { + if (colPath.indicatorKey) { + indicatorPosition = { + position: 'col', + index + }; + } + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any, index: number) => { + if (rowPath.indicatorKey) { + indicatorPosition = { + position: 'row', + index + }; + } + return rowPath.indicatorKey ?? rowPath.value; + }); const aggregator = this.dataset.getAggregator( // !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, // this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys, @@ -801,24 +817,32 @@ export class PivotTable extends BaseTable implements PivotTableAPI { } else if (this.dataset) { let indicatorPosition: { position: 'col' | 'row'; index?: number }; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => { - if (colPath.indicatorKey) { - indicatorPosition = { - position: 'col', - index - }; - } - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => { - if (rowPath.indicatorKey) { - indicatorPosition = { - position: 'row', - index - }; - } - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any, index: number) => { + if (colPath.indicatorKey) { + indicatorPosition = { + position: 'col', + index + }; + } + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any, index: number) => { + if (rowPath.indicatorKey) { + indicatorPosition = { + position: 'row', + index + }; + } + return rowPath.indicatorKey ?? rowPath.value; + }); const aggregator = this.dataset.getAggregator( // !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, // this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys, @@ -862,24 +886,32 @@ export class PivotTable extends BaseTable implements PivotTableAPI { } else if (this.dataset) { let indicatorPosition: { position: 'col' | 'row'; index?: number }; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => { - if (colPath.indicatorKey) { - indicatorPosition = { - position: 'col', - index - }; - } - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => { - if (rowPath.indicatorKey) { - indicatorPosition = { - position: 'row', - index - }; - } - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any, index: number) => { + if (colPath.indicatorKey) { + indicatorPosition = { + position: 'col', + index + }; + } + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any, index: number) => { + if (rowPath.indicatorKey) { + indicatorPosition = { + position: 'row', + index + }; + } + return rowPath.indicatorKey ?? rowPath.value; + }); const aggregator = this.dataset.getAggregator( // !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, // this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys, @@ -922,24 +954,32 @@ export class PivotTable extends BaseTable implements PivotTableAPI { } else if (this.dataset) { let indicatorPosition: { position: 'col' | 'row'; index?: number }; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => { - if (colPath.indicatorKey) { - indicatorPosition = { - position: 'col', - index - }; - } - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => { - if (rowPath.indicatorKey) { - indicatorPosition = { - position: 'row', - index - }; - } - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any, index: number) => { + if (colPath.indicatorKey) { + indicatorPosition = { + position: 'col', + index + }; + } + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any, index: number) => { + if (rowPath.indicatorKey) { + indicatorPosition = { + position: 'row', + index + }; + } + return rowPath.indicatorKey ?? rowPath.value; + }); const aggregator = this.dataset.getAggregator( // !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, // this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys, @@ -1777,12 +1817,20 @@ export class PivotTable extends BaseTable implements PivotTableAPI { newValue ); } else { - const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => { - return colPath.indicatorKey ?? colPath.value; - }); - const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => { - return rowPath.indicatorKey ?? rowPath.value; - }); + const colKeys = cellDimensionPath.colHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((colPath: any) => { + return colPath.indicatorKey ?? colPath.value; + }); + const rowKeys = cellDimensionPath.rowHeaderPaths + ?.filter((path: any) => { + return !path.virtual; + }) + .map((rowPath: any) => { + return rowPath.indicatorKey ?? rowPath.value; + }); this.dataset.changeTreeNodeValue( !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys, this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,