Skip to content

Commit 376326a

Browse files
committed
fix: 开启自定义行列头时, 不应该渲染总计节点和组内排序 icon closes #2898 #2893
1 parent c40bbf9 commit 376326a

File tree

10 files changed

+91
-69
lines changed

10 files changed

+91
-69
lines changed

packages/s2-core/__tests__/spreadsheet/custom-grid-spec.ts

+51-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ describe('SpreadSheet Custom Grid Tests', () => {
254254
s2.facet.getRowNodes().every((node) => node.isCollapsed),
255255
).toBeTruthy();
256256
});
257+
258+
// https://github.com/antvis/S2/issues/2898
259+
test('should not render sort action icon for custom row header', async () => {
260+
s2.setOptions({
261+
showDefaultHeaderActionIcon: true,
262+
});
263+
264+
await s2.render(false);
265+
266+
s2.facet.getRowCells().forEach((cell) => {
267+
expect(cell.getActionIcons()).toHaveLength(0);
268+
});
269+
});
257270
});
258271

259272
describe('Custom Col Grid Tests', () => {
@@ -276,7 +289,7 @@ describe('SpreadSheet Custom Grid Tests', () => {
276289
});
277290

278291
afterEach(() => {
279-
s2.destroy();
292+
// s2.destroy();
280293
});
281294

282295
test('should enable valueInCols', () => {
@@ -538,5 +551,42 @@ describe('SpreadSheet Custom Grid Tests', () => {
538551
s2.facet.getColNodes().some((node) => node.isCollapsed),
539552
).toBeFalsy();
540553
});
554+
555+
// https://github.com/antvis/S2/issues/2893
556+
test.each(['tree', 'grid'])(
557+
'should not render total node for %s mode',
558+
async (hierarchyType) => {
559+
s2.setOptions({
560+
hierarchyType,
561+
totals: {
562+
col: {
563+
showGrandTotals: true,
564+
reverseGrandTotalsLayout: true,
565+
},
566+
row: {
567+
showGrandTotals: true,
568+
reverseGrandTotalsLayout: true,
569+
},
570+
},
571+
});
572+
573+
await s2.render(false);
574+
575+
expect(s2.facet.getColGrandTotalsNodes()).toHaveLength(0);
576+
expect(s2.facet.getRowGrandTotalsNodes()).toHaveLength(0);
577+
},
578+
);
579+
580+
test('should not render sort action icon for custom col header', async () => {
581+
s2.setOptions({
582+
showDefaultHeaderActionIcon: true,
583+
});
584+
585+
await s2.render(false);
586+
587+
s2.facet.getColCells().forEach((cell) => {
588+
expect(cell.getActionIcons()).toHaveLength(0);
589+
});
590+
});
541591
});
542592
});

packages/s2-core/src/cell/header-cell.ts

+5
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ export abstract class HeaderCell<
335335
}
336336

337337
protected isSortCell() {
338+
// https://github.com/antvis/S2/issues/2898
339+
if (this.meta.extra?.isCustomNode) {
340+
return false;
341+
}
342+
338343
// 数值置于列头, 排序 icon 绘制在列头叶子节点; 置于行头, 排序 icon 绘制在行头叶子节点
339344
const isValueInCols = this.spreadsheet?.isValueInCols?.();
340345
const isMaxLevel = this.meta.level === this.meta.hierarchy?.maxLevel;

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ const buildNormalGridHierarchy = (params: GridHeaderParams) => {
114114
}
115115
}
116116

117-
// add totals if needed
118-
addTotals({
119-
currentField,
120-
lastField: fields[index - 1],
121-
isFirstField: index === 0,
122-
fieldValues,
123-
spreadsheet,
124-
});
117+
// https://github.com/antvis/S2/issues/2893
118+
if (!spreadsheet.isCustomHeaderFields()) {
119+
addTotals({
120+
currentField,
121+
lastField: fields[index - 1],
122+
isFirstField: index === 0,
123+
fieldValues,
124+
spreadsheet,
125+
});
126+
}
125127

126128
const displayFieldValues = filterOutDetail(fieldValues as string[]);
127129

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const buildRowTreeHierarchy = (params: TreeHeaderParams) => {
6161
fieldValues = fieldValues.slice(0, drillItemsNum);
6262
}
6363

64-
if (level === 0) {
64+
if (level === 0 && !spreadsheet.isCustomHeaderFields()) {
6565
addTotals(spreadsheet, currentField, fieldValues);
6666
}
6767

packages/s2-react/playground/components/CustomGrid.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const pivotSheetCustomColGridDataCfg: S2DataConfig = {
7878
enum CustomType {
7979
Row = 'row',
8080
Col = 'col',
81-
All = 'all',
8281
}
8382

8483
type CustomGridProps = Partial<SheetComponentProps>;
@@ -122,9 +121,6 @@ export const CustomGrid = React.forwardRef<SpreadSheet, CustomGridProps>(
122121
>
123122
<Radio.Button value={CustomType.Row}>自定义行头</Radio.Button>
124123
<Radio.Button value={CustomType.Col}>自定义列头</Radio.Button>
125-
<Radio.Button value={CustomType.All} disabled>
126-
TODO: 自定义行头和列头
127-
</Radio.Button>
128124
</Radio.Group>
129125
<Switch
130126
checkedChildren="树状模式"

s2-site/docs/common/totals.zh.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ order: 3
99

1010
| 参数 | 说明 | 类型 | 必选 | 默认值 |
1111
| ---- | ------ | --------------------------------------------- | ---- | ------ |
12-
| row | 行总计配置 | [Total](/docs/api/general/S2Options#total) | | |
13-
| col | 列总计配置 | [Total](/docs/api/general/S2Options#total) | | |
12+
| row | 列总计(在 [自定义行列头时](/manual/advanced/custom/custom-header) 无效) | [Total](#total) | - | |
13+
| col | 行总计(在 [自定义行列头时](/manual/advanced/custom/custom-header) 无效) | [Total](#total) | - | |
1414

1515
## Total
1616

s2-site/docs/manual/advanced/custom/custom-header.zh.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ tag: New
66

77
`S2` 默认提供 [平铺模式 (grid)](https://s2.antv.vision/zh/examples/basic/pivot#grid)[树状模式 (tree)](https://s2.antv.vision/zh/examples/basic/pivot#tree) 两种**行头**单元格布局方式。
88

9-
默认通过**分组之后得到的数据生成层级结构**, 如果都不满足的话,可以通过自定义行列头,来定制你的目录结构,同样兼容平铺和树状这两种布局方式。
9+
默认通过**分组之后得到的数据生成层级结构**, 如果都不满足,还可以通过自定义行列头,来定制你的目录结构,同样兼容平铺和树状这两种布局方式。
10+
11+
## 一些限制
12+
13+
:::warning{title="注意"}
14+
15+
1. 默认的排序 icon `showDefaultHeaderActionIcon` 无效。
16+
2. 不支持 [组内排序](/manual/basic/sort/group), 相关 API 无效。
17+
3. 不支持 [小计总计](/manual/basic/totals), 且 [自定义汇总](/manual/basic/totals#2-%E6%95%B0%E6%8D%AE) 中无法获取到明细数据。
18+
19+
:::
1020

1121
## 数据结构
1222

s2-site/docs/manual/basic/sort/group.zh.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ tag: Updated
99
`组内排序` 代表只影响一个分组内部的排序,例如下图中 `笔-价格` 选择 `组内升序` 时,`省份` 的排序方式不会更改,只会更改每个 `省份` 内部 `城市` 的顺序。
1010

1111
:::warning{title="注意"}
12-
`行头/列头` 只存在单一状态,当前状态会覆盖前一状态,如上图所示,当对 `` 进行排序时,`纸张` 的排序状态消失,`行头 + 列头` 可同时存在自身状态。
12+
13+
1. `行头/列头` 只存在单一状态,当前状态会**覆盖前一状态**,如上图所示,当对 `` 进行排序时,`纸张` 的排序状态消失,`行头 + 列头` 可同时存在自身状态。
14+
2. 在开启 [自定义行列头时](/manual/advanced/custom/custom-header) 组内排序无效。
15+
1316
:::
1417

1518
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*PuoGS7DQdV8AAAAAAAAAAAAADmJ7AQ/original" width="600" alt="group-sort" />

s2-site/docs/manual/basic/totals.zh.md

+5-50
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ order: 5
55

66
## 简介
77

8-
小计总计属于表的透视功能,可以给行头和列头分别配置小计总计
8+
小计总计属于表的透视功能,可以给行头和列头分别配置汇总能力,展示小计总计,开启 [自定义行列头](/manual/advanced/custom/custom-header) 时,汇总能力无效
99

1010
### 小计
1111

@@ -81,53 +81,7 @@ order: 5
8181

8282
配置 [S2Options](/docs/api/general/S2Options#total)`totals` 属性来实现是否展示行列小计总计以及显示位置,类型如下:
8383

84-
#### Totals
85-
86-
功能描述: 行/列小计总计配置
87-
88-
| 参数 | 说明 | 类型 | 默认值 | 必选 |
89-
| ---- | ------ | --------------------------------------------- | ------ | ---- |
90-
| row | 列总计 | [Total](/docs/api/general/S2Options#total) | - | |
91-
| col | 行总计 | [Total](/docs/api/general/S2Options#total) | - | |
92-
93-
#### Total
94-
95-
功能描述:小计总计算配置
96-
97-
| 参数 | 说明 | 类型 | 默认值 | 必选 |
98-
| ------------------- | ------------------------ | ------------ | ------ | ---- |
99-
| showGrandTotals | 是否显示总计 | `boolean` | false | |
100-
| showSubTotals | 是否显示小计。配置为对象时,`always` 用于控制当子维度小于 2 个时是否始终展示小计,默认展示 | `boolean \| { always: boolean }` | false | |
101-
| subTotalsDimensions | 小计的汇总维度 | `string[]` | [] | |
102-
| reverseGrandTotalsLayout | 总计布局位置,默认下或右 | `boolean` | false | |
103-
| reverseSubTotalsLayout | 小计布局位置,默认下或右 | `boolean` | false | |
104-
| grandTotalsLabel | 总计别名 | `string` | `总计` | |
105-
| subTotalsLabel | 小计别名 | `string` | `小计` | |
106-
| calcGrandTotals | 计算总计 | `CalcTotals` | | |
107-
| calcSubTotals | 计算小计 | `CalcTotals` | | |
108-
109-
```ts
110-
const s2Options = {
111-
totals: {
112-
row: {
113-
showGrandTotals: true,
114-
showSubTotals: true,
115-
reverseGrandTotalsLayout: true,
116-
reverseSubTotalsLayout: true,
117-
subTotalsDimensions: ['province'],
118-
grandTotalsGroupDimensions: ['city'],
119-
subTotalsGroupDimensions: ['type', 'sub_type'],
120-
},
121-
col: {
122-
showGrandTotals: true,
123-
showSubTotals: true,
124-
reverseGrandTotalsLayout: true,
125-
reverseSubTotalsLayout: true,
126-
subTotalsDimensions: ['type'],
127-
},
128-
},
129-
};
130-
```
84+
<embed src="@/docs/common/totals.zh.md"></embed>
13185

13286
### 2. 数据
13387

@@ -269,11 +223,12 @@ const s2Options = {
269223

270224
注意:`data` 为明细数据,如需获取包含汇总的数据
271225

272-
```ts
226+
```ts | pure
273227
import { QueryDataType } from '@antv/s2';
274228

275229
const calcFunc = (query, data, spreadsheet) => {
276-
const allData = spreadsheet.dataSet.getMultiData(query, {
230+
const allData = spreadsheet.dataSet.getMultiData({
231+
query,
277232
queryType: QueryDataType.All,
278233
});
279234

s2-site/examples/analysis/totals/demo/custom.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ fetch('https://render.alipay.com/p/yuyan/180020010001215413/s2/basic.json')
3939
};
4040

4141
const calcFunc: CalcTotals['calcFunc'] = (query, data, spreadsheet) => {
42-
const allData = spreadsheet.dataSet.getMultiData(query, {
42+
const allData = spreadsheet.dataSet.getCellMultiData({
43+
query,
4344
queryType: QueryDataType.All,
4445
});
4546

0 commit comments

Comments
 (0)