|
| 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 | +} |
0 commit comments