Skip to content

Commit bc92eec

Browse files
authored
Merge pull request #3237 from VisActor/feat-custom-merge-config
feat: customMergeCell support array config #3202
2 parents 202b6c0 + bffea6c commit bc92eec

File tree

9 files changed

+51
-7
lines changed

9 files changed

+51
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vtable",
5+
"comment": "feat: customMergeCell support array config #3202",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vtable"
10+
}

docs/assets/guide/en/basic_function/merge_cell.md

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ In VTable, you can configure `customMergeCell` to customize the merging method o
111111
* range: merged range
112112
* style: style of merged cells
113113

114+
`customMergeCell` can also be configured as an array of merge rules. Each item in the array is a merge rule. The configuration of the rule is the same as the return value of the `customMergeCell` callback function.
115+
114116
### Example
115117

116118
```javascript livedemo template=vtable

docs/assets/guide/zh/basic_function/merge_cell.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ window['tableInstance'] = tableInstance;
106106

107107
## 自定义单元格合并
108108

109-
在VTable中,可以配置`customMergeCell`自定义单元格的合并方式,这种方式常用来显示一些标注信息。其中`customMergeCell`回调函数会传入行列号和表格实例,在函数中判断需要合并的单元格,并返回相应的合并规则:
109+
在VTable中,可以配置`customMergeCell`自定义单元格的合并方式,这种方式常用来显示一些标注信息。其中`customMergeCell`可以配置回调函数会传入行列号和表格实例,在函数中判断需要合并的单元格,并返回相应的合并规则:
110110
* text: 合并单元格内的文字
111111
* range: 合并的范围
112112
* style: 合并单元格的样式
113113

114+
`customMergeCell`也可以配置为合并规则的数组,数组中的每一项为一个合并规则,规则的配置与`customMergeCell`回调函数的返回值相同。
115+
114116
### 示例
115117

116118
```javascript livedemo template=vtable

docs/assets/option/en/common/option-secondary.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Table scrolling behavior, can be set: 'auto'|'none', the default value is 'auto'
444444
'none': don't triggers the browser's default behavior when the table scrolls to the top or bottom;
445445
```
446446

447-
#${prefix} customMergeCell(Function)
447+
#${prefix} customMergeCell(Function|Object)
448448
Customize cell merging rules. When the incoming row and column numbers are within the target area, the merging rules are returned:
449449

450450
- text: Merge text in cells
@@ -476,6 +476,8 @@ Customize cell merging rules. When the incoming row and column numbers are withi
476476
477477
```
478478

479+
`customMergeCell` can also be configured as an array of merge rules. Each item in the array is a merge rule. The configuration of the rule is the same as the return value of the `customMergeCell` callback function.
480+
479481
#${prefix} customCellStyle(Array)
480482

481483
```

docs/assets/option/zh/common/option-secondary.md

+2
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ html 目前实现较完整,先默认使用 html 渲染方式。目前暂不支
472472
473473
```
474474

475+
`customMergeCell`也可以配置为合并规则的数组,数组中的每一项为一个合并规则,规则的配置与`customMergeCell`回调函数的返回值相同。
476+
475477
#${prefix} customCellStyle(Array)
476478

477479
```

packages/vtable/src/core/BaseTable.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import type { ITableAnimationOption } from '../ts-types/animation/appear';
152152
import { checkCellInSelect } from '../state/common/check-in-select';
153153
import type { CustomCellStylePlugin, ICustomCellStylePlugin } from '../plugins/custom-cell-style';
154154
import { isCellDisableSelect } from '../state/select/is-cell-select-highlight';
155+
import { getCustomMergeCellFunc } from './utils/get-custom-merge-cell-func';
155156
import { vglobal } from '@src/vrender';
156157

157158
const { toBoxArray } = utilStyle;
@@ -508,7 +509,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
508509

509510
internalProps.stick = { changedCells: new Map() };
510511

511-
internalProps.customMergeCell = options.customMergeCell;
512+
internalProps.customMergeCell = getCustomMergeCellFunc(options.customMergeCell);
512513

513514
const CustomCellStylePlugin = Factory.getComponent('customCellStylePlugin') as ICustomCellStylePlugin;
514515
if (CustomCellStylePlugin) {
@@ -2473,7 +2474,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
24732474
this.clearColWidthCache();
24742475
this.clearRowHeightCache();
24752476

2476-
internalProps.customMergeCell = options.customMergeCell;
2477+
internalProps.customMergeCell = getCustomMergeCellFunc(options.customMergeCell);
24772478

24782479
this.customCellStylePlugin?.updateCustomCell(
24792480
options.customCellStyle ?? [],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { isArray, isFunction } from '@visactor/vutils';
2+
import type { CustomMergeCell } from '../../ts-types';
3+
4+
export function getCustomMergeCellFunc(customMergeCell?: CustomMergeCell) {
5+
if (isFunction(customMergeCell)) {
6+
return customMergeCell;
7+
}
8+
if (isArray(customMergeCell)) {
9+
return (col: number, row: number) => {
10+
return customMergeCell.find(item => {
11+
return (
12+
item.range.start.col <= col &&
13+
item.range.end.col >= col &&
14+
item.range.start.row <= row &&
15+
item.range.end.row >= row
16+
);
17+
});
18+
};
19+
}
20+
return undefined;
21+
}

packages/vtable/src/ts-types/base-table.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ import type {
7272
ColumnInfo,
7373
RowInfo,
7474
CellAddressWithBound,
75-
Placement
75+
Placement,
76+
CustomMergeCellFunc
7677
} from '.';
7778
import type { TooltipOptions } from './tooltip';
7879
import type { IWrapTextGraphicAttribute } from '../scenegraph/graphic/text';
@@ -256,7 +257,7 @@ export interface IBaseTableProtected {
256257

257258
stick: { changedCells: Map<string, StickCell> };
258259

259-
customMergeCell?: CustomMergeCell;
260+
customMergeCell?: CustomMergeCellFunc;
260261
/**
261262
* 'auto':和浏览器滚动行为一致 表格滚动到顶部/底部时 触发浏览器默认行为;
262263
* 设置为 'none' 时, 表格滚动到顶部/底部时, 不再触发父容器滚动

packages/vtable/src/ts-types/table-engine.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ export interface IExtensionRowDefine {
603603

604604
export type StickCell = { col: number; row: number; dx: number; dy: number };
605605

606-
export type CustomMergeCell = (col: number, row: number, table: BaseTableAPI) => undefined | CustomMerge;
606+
export type CustomMergeCell = CustomMergeCellFunc | CustomMergeCellArray;
607+
608+
export type CustomMergeCellFunc = (col: number, row: number, table: BaseTableAPI) => undefined | CustomMerge;
609+
export type CustomMergeCellArray = CustomMerge[];
607610
export type CustomMerge = {
608611
range: CellRange;
609612
text?: string;

0 commit comments

Comments
 (0)