Skip to content

Commit ae5de6c

Browse files
author
yingying.xwy
committed
fix(s2-react): 修复 hierarchyType 切换导致的渲染问题
1 parent 71c0093 commit ae5de6c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEmpty, merge, isBoolean, keys } from 'lodash';
1+
import { isEmpty, merge, isBoolean } from 'lodash';
22
import { FieldValue, TreeHeaderParams } from '@/facet/layout/interface';
33
import { layoutArrange, layoutHierarchy } from '@/facet/layout/layout-hooks';
44
import { TotalClass } from '@/facet/layout/total-class';

packages/s2-react/src/components/sheets/strategy-sheet/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ export const StrategySheet: React.FC<SheetComponentsProps> = React.memo(
3737
return {};
3838
}
3939
let hideMeasureColumn = false;
40+
let hierarchyType = 'tree';
41+
42+
// 根据 dataConfig 切换 hierarchyType
43+
if (
44+
isEmpty(dataCfg?.fields?.rows) &&
45+
!isEmpty(dataCfg?.fields?.customTreeItems)
46+
) {
47+
hierarchyType = 'customTree';
48+
}
49+
50+
// 单指标非自定义树结构隐藏指标列
4051
if (
4152
size(dataCfg?.fields?.values) === 1 &&
4253
options.hierarchyType !== 'customTree'
@@ -52,7 +63,7 @@ export const StrategySheet: React.FC<SheetComponentsProps> = React.memo(
5263
headerConfig: ColHeaderConfig,
5364
) => new CustomColCell(node, spreadsheet, headerConfig),
5465
showDefaultHeaderActionIcon: false,
55-
hierarchyType: isEmpty(dataCfg?.fields?.rows) ? 'customTree' : 'tree',
66+
hierarchyType,
5667

5768
style: {
5869
colCfg: {
@@ -97,7 +108,7 @@ export const StrategySheet: React.FC<SheetComponentsProps> = React.memo(
97108
},
98109
},
99110
};
100-
}, [dataCfg]);
111+
}, [dataCfg, options.hierarchyType]);
101112

102113
const s2DataCfg = React.useMemo(() => {
103114
const defaultFields = {

packages/s2-react/src/hooks/useSpreadSheet.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ export function useSpreadSheet(
7878
}
7979

8080
if (!Object.is(prevOptions, options)) {
81-
if (
82-
!Object.is(prevOptions?.hierarchyType, options?.hierarchyType) &&
83-
Object.is(options?.hierarchyType, 'customTree')
84-
) {
81+
if (!Object.is(prevOptions?.hierarchyType, options?.hierarchyType)) {
8582
// 自定义树目录需要重新构建 CustomTreePivotDataSet
8683
reBuildDataSet = true;
8784
reloadData = true;

0 commit comments

Comments
 (0)