From 81ffb0d2a80e3dbcbcd7a483f13919564fcce380 Mon Sep 17 00:00:00 2001 From: wjgogogo <906626481@qq.com> Date: Mon, 28 Oct 2024 11:37:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=A1=8C=E5=88=97=E5=A4=B4=E5=AF=B9=E6=80=BB=E8=AE=A1?= =?UTF-8?q?=E5=B0=8F=E8=AE=A1=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data-set/custom-tree-pivot-data-set.ts | 35 ----------- .../s2-core/src/sheet-type/pivot-sheet.ts | 4 +- .../playground/components/CustomGrid.tsx | 58 ++++++++++++++++++- 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts b/packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts index 3dd13ae9fd..9ce3a4b853 100644 --- a/packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts +++ b/packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts @@ -1,44 +1,9 @@ -import { get, type PropertyPath } from 'lodash'; import { EXTRA_FIELD } from '../common/constant'; import { i18n } from '../common/i18n'; import type { Meta, S2DataConfig } from '../common/interface'; -import { - getDataPath, - getDataPathPrefix, - getIndexFields, - transformDimensionsValues, -} from '../utils/dataset/pivot-data-set'; -import { CellData } from './cell-data'; -import type { GetCellDataParams } from './interface'; import { PivotDataSet } from './pivot-data-set'; export class CustomTreePivotDataSet extends PivotDataSet { - getCellData(params: GetCellDataParams) { - const { query = {} } = params || {}; - const { columns, rows } = this.fields; - - const indexRows = getIndexFields(rows); - const indexColumns = getIndexFields(columns); - - const rowDimensionValues = transformDimensionsValues(query, indexRows); - const colDimensionValues = transformDimensionsValues(query, indexColumns); - const path = getDataPath({ - rowDimensionValues, - colDimensionValues, - rowPivotMeta: this.rowPivotMeta, - colPivotMeta: this.colPivotMeta, - rowFields: indexRows, - colFields: indexColumns, - prefix: getDataPathPrefix(indexRows, indexColumns), - }); - - const rawData = get(this.indexesData, path as PropertyPath); - - if (rawData) { - return CellData.getCellData(rawData, query[EXTRA_FIELD]); - } - } - processDataCfg(dataCfg: S2DataConfig): S2DataConfig { /** * 自定义行头有如下几个特点 diff --git a/packages/s2-core/src/sheet-type/pivot-sheet.ts b/packages/s2-core/src/sheet-type/pivot-sheet.ts index a9ffcd66ef..804a5b94f3 100644 --- a/packages/s2-core/src/sheet-type/pivot-sheet.ts +++ b/packages/s2-core/src/sheet-type/pivot-sheet.ts @@ -144,10 +144,10 @@ export class PivotSheet extends SpreadSheet { const { rows, columns } = this.dataCfg.fields; const { hideValue } = this.options.style!.colCell!; const sortField = this.isValueInCols() ? last(rows) : last(columns); - const { query, value } = meta; + const { query, field, value, extra } = meta; const sortQuery = clone(query); - let sortValue = value; + let sortValue = extra?.isCustomNode ? field : value; // 数值置于列头且隐藏了指标列头的情况, 会默认取第一个指标做组内排序, 需要还原指标列的 query, 所以多指标时请不要这么用…… if (hideValue && this.isValueInCols()) { diff --git a/packages/s2-react/playground/components/CustomGrid.tsx b/packages/s2-react/playground/components/CustomGrid.tsx index 38a2ef6d7f..0f01c42a2d 100644 --- a/packages/s2-react/playground/components/CustomGrid.tsx +++ b/packages/s2-react/playground/components/CustomGrid.tsx @@ -1,5 +1,10 @@ /* eslint-disable no-console */ -import type { S2DataConfig, SpreadSheet, ThemeCfg } from '@antv/s2'; +import { + Aggregation, + type S2DataConfig, + type SpreadSheet, + type ThemeCfg, +} from '@antv/s2'; import { customColGridFields, customRowGridFields, @@ -154,6 +159,57 @@ export const CustomGrid = React.forwardRef( setSheetType(checked ? 'pivot' : 'table'); }} /> + + { + setOptions({ + totals: { + row: { + showGrandTotals: checked, + showSubTotals: checked, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, + subTotalsDimensions: ['province'], + calcGrandTotals: { + aggregation: Aggregation.SUM, + }, + calcSubTotals: { + aggregation: Aggregation.SUM, + }, + }, + }, + }); + }} + /> + { + setOptions({ + totals: { + col: { + showGrandTotals: checked, + showSubTotals: checked, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, + subTotalsDimensions: ['type'], + calcGrandTotals: { + aggregation: Aggregation.SUM, + }, + calcSubTotals: { + aggregation: Aggregation.SUM, + }, + }, + }, + }); + }} + />