Skip to content

Commit 33a0a38

Browse files
authored
Merge pull request #5086 from VisActor/feat/radio-aggregation-row-4027
Feat/radio aggregation row 4027
2 parents 7dd206d + c21226c commit 33a0a38

8 files changed

Lines changed: 192 additions & 23 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ packages/vtable/nodejs/*.png
107107
.rollup.cache/
108108
tsconfig.tsbuildinfo
109109

110-
.history
110+
.history
111+
.trae/
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: radio cell type with rowseriesnumber error\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "892739385@qq.com"
11+
}
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: degrade radio/checkbox cells to text in aggregation rows",
5+
"type": "patch",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "2779428708@qq.com"
11+
}

packages/vtable/examples/menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ export const menus = [
580580
path: 'type',
581581
name: 'radio'
582582
},
583+
{
584+
path: 'type',
585+
name: 'radio-aggregation'
586+
},
583587
{
584588
path: 'type',
585589
name: 'switch'
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as VTable from '../../src';
2+
import { AggregationType } from '../../src/ts-types';
3+
import { bindDebugTool } from '../../src/scenegraph/debug-tool';
4+
const ListTable = VTable.ListTable;
5+
const CONTAINER_ID = 'vTable';
6+
7+
/**
8+
* 验证场景:合计行中 radio 单元格应降级为文本单元格,与 checkbox 行为保持一致。
9+
* 对应 issue: https://github.com/VisActor/VTable/issues/4027
10+
*
11+
* 复现步骤(修复前):
12+
* 1. 表格配置了 bottomFrozenRowCount 和 aggregation(合计行)
13+
* 2. 某列配置 cellType: 'radio'
14+
* 3. 修复前:合计行中 radio 渲染异常,可能导致表格整体空白
15+
* 4. 修复后:合计行中 radio 列正确降级为纯文本显示,表格正常渲染
16+
*/
17+
export function createTable() {
18+
const data = [
19+
{ percent: '100%', value: 20, check: { text: 'unchecked', checked: false, disable: false } },
20+
{ percent: '80%', value: 18, check: { text: 'checked', checked: true, disable: false } },
21+
{ percent: '20%', value: 12, check: { text: 'unchecked', checked: false, disable: false } },
22+
{ percent: '0%', value: 10, check: { text: 'checked', checked: false, disable: false } },
23+
{ percent: '60%', value: 16, check: { text: 'disable', checked: true, disable: true } },
24+
{ percent: '40%', value: 14, check: { text: 'disable', checked: false, disable: true } },
25+
{ percent: '0%', value: -10, check: true },
26+
{ percent: '0%', value: -10, check: ['选中', '选中'] }
27+
];
28+
let records: any[] = [];
29+
for (let i = 0; i < 10; i++) {
30+
records = records.concat(data);
31+
}
32+
33+
const columns: VTable.ColumnsDefine = [
34+
{
35+
field: 'percent',
36+
title: 'percent',
37+
width: 120,
38+
sort: true
39+
},
40+
{
41+
field: 'value',
42+
title: 'value',
43+
width: 100,
44+
aggregation: [
45+
{
46+
aggregationType: AggregationType.SUM,
47+
formatFun(value) {
48+
return '合计: ' + Math.round(value);
49+
}
50+
}
51+
]
52+
},
53+
{
54+
field: 'percent',
55+
title: 'column radio',
56+
width: 120,
57+
cellType: 'radio'
58+
},
59+
{
60+
field: 'check',
61+
title: 'cell radio',
62+
width: 200,
63+
cellType: 'radio',
64+
radioCheckType: 'cell',
65+
radioDirectionInCell: 'vertical',
66+
style: {
67+
spaceBetweenRadio: 10
68+
}
69+
},
70+
{
71+
field: 'percent',
72+
title: 'checkbox',
73+
width: 120,
74+
cellType: 'checkbox',
75+
disable: true,
76+
checked: true
77+
}
78+
];
79+
80+
const option: VTable.ListTableConstructorOptions = {
81+
container: document.getElementById(CONTAINER_ID),
82+
columns,
83+
records,
84+
widthMode: 'standard',
85+
heightMode: 'autoHeight',
86+
bottomFrozenRowCount: 1,
87+
rowSeriesNumber: {
88+
width: 50,
89+
cellType: 'radio'
90+
},
91+
theme: VTable.themes.DEFAULT.extends({
92+
bottomFrozenStyle: {
93+
fontWeight: 500
94+
}
95+
})
96+
};
97+
98+
const instance = new ListTable(option);
99+
100+
bindDebugTool(instance.scenegraph.stage as any, {
101+
customGrapicKeys: ['role', '_updateTag']
102+
});
103+
104+
const { RADIO_STATE_CHANGE } = VTable.ListTable.EVENT_TYPE;
105+
instance.on(RADIO_STATE_CHANGE, e => {
106+
console.log('Radio state changed:', e.col, e.row, e.radioIndexInCell);
107+
});
108+
109+
(window as any).tableInstance = instance;
110+
}

packages/vtable/src/core/BaseTable.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
37653765
getCellType(col: number, row: number): ColumnTypeOption {
37663766
let cellType;
37673767
if (this.isSeriesNumberInHeader(col, row)) {
3768-
return (this.internalProps.layoutMap as SimpleHeaderLayoutMap).getSeriesNumberHeader(col, row).cellType;
3768+
const seriesHeaderCellType = (this.internalProps.layoutMap as SimpleHeaderLayoutMap).getSeriesNumberHeader(
3769+
col,
3770+
row
3771+
).cellType;
3772+
return seriesHeaderCellType === 'radio' ? 'text' : seriesHeaderCellType;
37693773
} else if (this.isHeader(col, row)) {
37703774
cellType = (this.internalProps.layoutMap.getHeader(col, row) as HeaderData).headerType;
37713775
} else {

packages/vtable/src/header-helper/header-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ export class HeaderHelper {
464464
return TextHeaderStyle;
465465
case 'checkbox':
466466
return CheckboxStyle;
467+
default:
468+
return TextHeaderStyle;
467469
}
468470
}
469471

packages/vtable/src/scenegraph/group-creater/cell-helper.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ export function createCell(
374374
} else if (type === 'checkbox') {
375375
const isAggregation =
376376
'isAggregation' in table.internalProps.layoutMap && table.internalProps.layoutMap.isAggregation(col, row);
377-
const isSeriesNumber = table.internalProps.layoutMap.isSeriesNumber(col, row);
378-
if (isAggregation && isSeriesNumber) {
377+
if (isAggregation) {
379378
const createTextCellGroup = Factory.getFunction('createTextCellGroup') as CreateTextCellGroup;
380379
cellGroup = createTextCellGroup(
381380
table,
@@ -423,25 +422,52 @@ export function createCell(
423422
);
424423
}
425424
} else if (type === 'radio') {
426-
const createRadioCellGroup = Factory.getFunction('createRadioCellGroup') as CreateRadioCellGroup;
427-
cellGroup = createRadioCellGroup(
428-
null,
429-
columnGroup,
430-
0,
431-
y,
432-
col,
433-
row,
434-
colWidth,
435-
cellWidth,
436-
cellHeight,
437-
padding,
438-
textAlign,
439-
textBaseline,
440-
table,
441-
cellTheme,
442-
define as RadioColumnDefine,
443-
range
444-
);
425+
const isAggregation =
426+
'isAggregation' in table.internalProps.layoutMap && table.internalProps.layoutMap.isAggregation(col, row);
427+
if (isAggregation) {
428+
const createTextCellGroup = Factory.getFunction('createTextCellGroup') as CreateTextCellGroup;
429+
cellGroup = createTextCellGroup(
430+
table,
431+
value,
432+
columnGroup,
433+
0,
434+
y,
435+
col,
436+
row,
437+
colWidth,
438+
cellWidth,
439+
cellHeight,
440+
padding,
441+
textAlign,
442+
textBaseline,
443+
false,
444+
undefined,
445+
true,
446+
cellTheme,
447+
range,
448+
isAsync
449+
);
450+
} else {
451+
const createRadioCellGroup = Factory.getFunction('createRadioCellGroup') as CreateRadioCellGroup;
452+
cellGroup = createRadioCellGroup(
453+
null,
454+
columnGroup,
455+
0,
456+
y,
457+
col,
458+
row,
459+
colWidth,
460+
cellWidth,
461+
cellHeight,
462+
padding,
463+
textAlign,
464+
textBaseline,
465+
table,
466+
cellTheme,
467+
define as RadioColumnDefine,
468+
range
469+
);
470+
}
445471
} else if (type === 'switch') {
446472
const createSwitchCellGroup = Factory.getFunction('createSwitchCellGroup') as CreateSwitchCellGroup;
447473
cellGroup = createSwitchCellGroup(

0 commit comments

Comments
 (0)