intable 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +378 -378
- package/dist/__uno.css +1 -1
- package/dist/style.css +2 -2
- package/dist/theme/antd.scss +42 -42
- package/dist/theme/dark.scss +46 -46
- package/dist/theme/element-plus.scss +38 -38
- package/dist/theme/github.scss +80 -80
- package/dist/theme/material.scss +73 -73
- package/dist/theme/shadcn.scss +66 -66
- package/dist/theme/stripe.scss +57 -57
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,379 +1,379 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: intable
|
|
3
|
-
description: A high-performance, plugin-based Excel-like table component for SolidJS with virtual scroll, cell editing, validation, copy/paste, row grouping, tree data, column/row drag, merge cells, diff view, and multi-framework support (Vue, React).
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# intable
|
|
7
|
-
|
|
8
|
-
## 特征
|
|
9
|
-
|
|
10
|
-
- 类似 Excel 的表格组件
|
|
11
|
-
- 单元格多选、复制、粘贴
|
|
12
|
-
- 单元格编辑、数据校验
|
|
13
|
-
- 列宽、行高可调整
|
|
14
|
-
- 列、行可拖拽
|
|
15
|
-
- 虚拟滚动
|
|
16
|
-
- 数据分组
|
|
17
|
-
- 行展开
|
|
18
|
-
- 树嵌套
|
|
19
|
-
- 插件易扩展
|
|
20
|
-
- 多框架支持(Vue、React)
|
|
21
|
-
- 多 UI库支持(Antd、ElementPlus)
|
|
22
|
-
|
|
23
|
-
## 快速开始
|
|
24
|
-
|
|
25
|
-
<details>
|
|
26
|
-
<summary>solid-js</summary>
|
|
27
|
-
|
|
28
|
-
**安装**
|
|
29
|
-
|
|
30
|
-
```sh
|
|
31
|
-
pnpm add intable
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
**使用**
|
|
35
|
-
|
|
36
|
-
```jsx
|
|
37
|
-
import Intable from 'intable'
|
|
38
|
-
|
|
39
|
-
const App = () => {
|
|
40
|
-
const columns = [
|
|
41
|
-
{ id: 'name', name: '名称' },
|
|
42
|
-
{ id: 'date', name: '日期' },
|
|
43
|
-
{ id: 'address', name: '地址' },
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
const data = [
|
|
47
|
-
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
48
|
-
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
49
|
-
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
50
|
-
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
return <Intable data={data} columns={columns} />
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
</details>
|
|
57
|
-
|
|
58
|
-
<details>
|
|
59
|
-
<summary>vue</summary>
|
|
60
|
-
|
|
61
|
-
**安装**
|
|
62
|
-
|
|
63
|
-
```sh
|
|
64
|
-
pnpm add @intable/vue
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**使用**
|
|
68
|
-
|
|
69
|
-
```html
|
|
70
|
-
<template>
|
|
71
|
-
<Intable :data="data" :columns="columns" />
|
|
72
|
-
</template>
|
|
73
|
-
|
|
74
|
-
<script setup>
|
|
75
|
-
import Intable from '@intable/vue'
|
|
76
|
-
|
|
77
|
-
const columns = [
|
|
78
|
-
{ id: 'name', name: '名称' },
|
|
79
|
-
{ id: 'date', name: '日期' },
|
|
80
|
-
{ id: 'address', name: '地址' },
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
const data = [
|
|
84
|
-
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
85
|
-
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
86
|
-
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
87
|
-
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
88
|
-
]
|
|
89
|
-
</script>
|
|
90
|
-
```
|
|
91
|
-
</details>
|
|
92
|
-
|
|
93
|
-
<details>
|
|
94
|
-
<summary>react</summary>
|
|
95
|
-
|
|
96
|
-
**安装**
|
|
97
|
-
|
|
98
|
-
```sh
|
|
99
|
-
pnpm add @intable/react
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
**使用**
|
|
103
|
-
|
|
104
|
-
```jsx
|
|
105
|
-
import Intable from '@intable/react'
|
|
106
|
-
|
|
107
|
-
const App = () => {
|
|
108
|
-
const columns = [
|
|
109
|
-
{ id: 'name', name: '名称' },
|
|
110
|
-
{ id: 'date', name: '日期' },
|
|
111
|
-
{ id: 'address', name: '地址' },
|
|
112
|
-
]
|
|
113
|
-
|
|
114
|
-
const data = [
|
|
115
|
-
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
116
|
-
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
117
|
-
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
118
|
-
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
return <Intable data={data} columns={columns} />
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
</details>
|
|
125
|
-
|
|
126
|
-
## Props
|
|
127
|
-
|
|
128
|
-
| 属性名 | 描述 | 类型 | 默认值 |
|
|
129
|
-
| ------------ | ------------ | ------------------------------- | ------- |
|
|
130
|
-
| data | 数据 | any[] | |
|
|
131
|
-
| columns | 展示列 | Column[] | |
|
|
132
|
-
| rowKey | 行唯一键字段 | string | `'id'` |
|
|
133
|
-
| index | 显示序号 | boolean | false |
|
|
134
|
-
| border | 显示纵向边框 | boolean | false |
|
|
135
|
-
| stickyHeader | 表头吸顶 | boolean | false |
|
|
136
|
-
| size | 尺寸 | `'large' \| 'default' \| 'small'` | — |
|
|
137
|
-
| plugins | 插件列表 | Plugin[] | `[]` |
|
|
138
|
-
|
|
139
|
-
## Column
|
|
140
|
-
|
|
141
|
-
| 属性名 | 描述 | 类型 |
|
|
142
|
-
| -------- | ---------------------- | ----------------------------- |
|
|
143
|
-
| id | 字段名,对应数据 key | string \| symbol |
|
|
144
|
-
| name | 表头显示名称 | string |
|
|
145
|
-
| width | 列宽(px) | number |
|
|
146
|
-
| fixed | 固定列 | `'left' \| 'right'` |
|
|
147
|
-
| render | 自定义渲染器 | `string \| Render` |
|
|
148
|
-
| enum |
|
|
149
|
-
| editable | 是否可编辑 | boolean |
|
|
150
|
-
| editor | 编辑器类型或自定义实现 | `string \| Editor` |
|
|
151
|
-
| resizable| 是否允许调整列宽 | boolean |
|
|
152
|
-
|
|
153
|
-
## 插件
|
|
154
|
-
|
|
155
|
-
插件通过 `plugins` 属性传入,部分插件需从对应路径手动引入。
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
### VirtualScrollPlugin — 虚拟滚动
|
|
160
|
-
|
|
161
|
-
大数据量下只渲染可见行列,显著提升性能。
|
|
162
|
-
|
|
163
|
-
```jsx
|
|
164
|
-
import { VirtualScrollPlugin } from 'intable/plugins/VirtualScrollPlugin'
|
|
165
|
-
|
|
166
|
-
<Intable
|
|
167
|
-
plugins={[VirtualScrollPlugin]}
|
|
168
|
-
virtual={{
|
|
169
|
-
y: { estimateSize: () => 40, overscan: 10 }, // 行虚拟化参数
|
|
170
|
-
x: { overscan: 5 }, // 列虚拟化参数
|
|
171
|
-
}}
|
|
172
|
-
/>
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
### EditablePlugin — 单元格编辑
|
|
178
|
-
|
|
179
|
-
在 Column 上设置 `editable: true` 开启单元格编辑,双击或输入字符进入编辑状态。
|
|
180
|
-
|
|
181
|
-
```jsx
|
|
182
|
-
const columns = [
|
|
183
|
-
{ id: 'name', name: '姓名', editable: true },
|
|
184
|
-
{ id: 'age', name: '年龄', editable: true, editor: 'number' },
|
|
185
|
-
{ id: 'type', name: '类型', editable: true, editor: 'select', enum: { 1: 'A', 2: 'B' } },
|
|
186
|
-
{ id: 'date', name: '日期', editable: true, editor: 'date' },
|
|
187
|
-
]
|
|
188
|
-
|
|
189
|
-
<Intable columns={columns} onDataChange={setData} />
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
内置编辑器类型:`text`(默认)、`number`、`select`、`date`、`time`、`datetime`、`switch`、`checkbox`、`rate`、`color`、`file`。
|
|
193
|
-
|
|
194
|
-
搭配 UI 库插件可直接使用对应组件:
|
|
195
|
-
- **Antd**:`import { AntdPlugin } from '@intable/react/plugins/antd'`
|
|
196
|
-
- **Element Plus**:`import { ElementPlusPlugin } from '@intable/vue/plugins/element-plus'`
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
### RowSelectionPlugin — 行选择
|
|
201
|
-
|
|
202
|
-
```jsx
|
|
203
|
-
<Intable
|
|
204
|
-
rowSelection={{
|
|
205
|
-
enable: true,
|
|
206
|
-
multiple: true, // 多选,默认 true
|
|
207
|
-
value: selectedRows, // 受控选中值
|
|
208
|
-
selectable: row => row.age > 18, // 可选条件
|
|
209
|
-
onChange: rows => setSelected(rows),
|
|
210
|
-
}}
|
|
211
|
-
/>
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
---
|
|
215
|
-
|
|
216
|
-
### ExpandPlugin — 行展开
|
|
217
|
-
|
|
218
|
-
点击行首箭头展开自定义内容区域。
|
|
219
|
-
|
|
220
|
-
```jsx
|
|
221
|
-
<Intable
|
|
222
|
-
expand={{
|
|
223
|
-
enable: true,
|
|
224
|
-
render: ({ data, y }) => <div>详情:{data.name}</div>,
|
|
225
|
-
}}
|
|
226
|
-
/>
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
### RowGroupPlugin — 行分组
|
|
232
|
-
|
|
233
|
-
按指定字段对行进行分级树形分组,支持展开/折叠。
|
|
234
|
-
|
|
235
|
-
```jsx
|
|
236
|
-
<Intable
|
|
237
|
-
rowGroup={{ fields: ['type', 'subType'] }}
|
|
238
|
-
/>
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
|
-
### TreePlugin — 树形数据
|
|
244
|
-
|
|
245
|
-
渲染嵌套 `children` 字段的树状数据,支持展开/折叠,自动缩进。
|
|
246
|
-
|
|
247
|
-
```jsx
|
|
248
|
-
const data = [
|
|
249
|
-
{ id: 1, name: '总部', children: [
|
|
250
|
-
{ id: 2, name: '研发部' },
|
|
251
|
-
{ id: 3, name: '产品部', children: [
|
|
252
|
-
{ id: 4, name: '设计组' },
|
|
253
|
-
]},
|
|
254
|
-
]},
|
|
255
|
-
]
|
|
256
|
-
|
|
257
|
-
<Intable
|
|
258
|
-
tree={{ children: 'children' }} // 子节点字段名,默认 'children'
|
|
259
|
-
data={data}
|
|
260
|
-
columns={[{ id: 'name', name: '名称' }]}
|
|
261
|
-
/>
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
### ResizePlugin — 调整列宽 / 行高
|
|
267
|
-
|
|
268
|
-
拖动表头右侧边框调整列宽,拖动行底部边框调整行高。
|
|
269
|
-
|
|
270
|
-
```jsx
|
|
271
|
-
<Intable
|
|
272
|
-
resizable={{
|
|
273
|
-
col: { enable: true, min: 60, max: 600 },
|
|
274
|
-
row: { enable: true, min: 28, max: 200 },
|
|
275
|
-
}}
|
|
276
|
-
onColumnsChange={cols => setColumns(cols)}
|
|
277
|
-
/>
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
也可在单列上单独控制:
|
|
281
|
-
|
|
282
|
-
```js
|
|
283
|
-
{ id: 'name', name: '姓名', resizable: false } // 禁止该列拖拽
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
---
|
|
287
|
-
|
|
288
|
-
### DragPlugin — 列 / 行拖拽排序
|
|
289
|
-
|
|
290
|
-
长按后拖拽列标题或行首单元格可重新排序。
|
|
291
|
-
|
|
292
|
-
```jsx
|
|
293
|
-
<Intable
|
|
294
|
-
colDrag={true} // 开启列拖拽
|
|
295
|
-
rowDrag={true} // 开启行拖拽
|
|
296
|
-
onColumnsChange={cols => setColumns(cols)}
|
|
297
|
-
/>
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
---
|
|
301
|
-
|
|
302
|
-
### HistoryPlugin — 撤销 / 重做
|
|
303
|
-
|
|
304
|
-
记录数据变更历史,支持 `Ctrl+Z` / `Ctrl+Y`。
|
|
305
|
-
|
|
306
|
-
```jsx
|
|
307
|
-
import { HistoryPlugin } from 'intable/plugins/HistoryPlugin'
|
|
308
|
-
|
|
309
|
-
<Intable plugins={[HistoryPlugin]} />
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
通过命令调用:
|
|
313
|
-
```js
|
|
314
|
-
store.history.undo()
|
|
315
|
-
store.history.redo()
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
---
|
|
319
|
-
|
|
320
|
-
### DiffPlugin — 数据差异对比
|
|
321
|
-
|
|
322
|
-
将当前数据与快照进行比较,高亮新增/删除/修改行,支持提交。
|
|
323
|
-
|
|
324
|
-
```jsx
|
|
325
|
-
import { DiffPlugin } from 'intable/plugins/DiffPlugin'
|
|
326
|
-
|
|
327
|
-
<Intable
|
|
328
|
-
plugins={[DiffPlugin]}
|
|
329
|
-
diff={{
|
|
330
|
-
added: true, // 高亮新增行,默认 true
|
|
331
|
-
removed: true, // 高亮删除行,默认 true
|
|
332
|
-
changed: true, // 高亮修改行,默认 true
|
|
333
|
-
onCommit: (data, { added, removed, changed }) => save(data),
|
|
334
|
-
}}
|
|
335
|
-
/>
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
`Ctrl+S` 触发提交,或通过命令:
|
|
339
|
-
```js
|
|
340
|
-
store.commands.diffCommit()
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
---
|
|
344
|
-
|
|
345
|
-
### CellMergePlugin — 单元格合并
|
|
346
|
-
|
|
347
|
-
通过 `merge` 回调或 Column 的 `mergeRow` 快捷属性合并相邻单元格。
|
|
348
|
-
|
|
349
|
-
```jsx
|
|
350
|
-
// 方式一:全局 merge 回调
|
|
351
|
-
<Intable
|
|
352
|
-
merge={(row, col, y, x) => {
|
|
353
|
-
if (col.id === 'name') {
|
|
354
|
-
let rowspan = 1
|
|
355
|
-
while (data[y + rowspan]?.name === row.name) rowspan++
|
|
356
|
-
return rowspan > 1 ? { rowspan } : null
|
|
357
|
-
}
|
|
358
|
-
}}
|
|
359
|
-
/>
|
|
360
|
-
|
|
361
|
-
// 方式二:列级 mergeRow 快捷属性(自动合并相邻等值行)
|
|
362
|
-
const columns = [
|
|
363
|
-
{ id: 'type', name: '类型', mergeRow: true },
|
|
364
|
-
{ id: 'name', name: '名称' },
|
|
365
|
-
]
|
|
366
|
-
<Intable columns={columns} />
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
---
|
|
370
|
-
|
|
371
|
-
### CellSelectionPlugin — 单元格多选
|
|
372
|
-
|
|
373
|
-
鼠标拖拽或 `Shift+点击` 选择矩形区域,箭头键移动焦点。
|
|
374
|
-
|
|
375
|
-
---
|
|
376
|
-
|
|
377
|
-
### CopyPastePlugin — 复制粘贴
|
|
378
|
-
|
|
1
|
+
---
|
|
2
|
+
name: intable
|
|
3
|
+
description: A high-performance, plugin-based Excel-like table component for SolidJS with virtual scroll, cell editing, validation, copy/paste, row grouping, tree data, column/row drag, merge cells, diff view, and multi-framework support (Vue, React).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# intable
|
|
7
|
+
|
|
8
|
+
## 特征
|
|
9
|
+
|
|
10
|
+
- 类似 Excel 的表格组件
|
|
11
|
+
- 单元格多选、复制、粘贴
|
|
12
|
+
- 单元格编辑、数据校验
|
|
13
|
+
- 列宽、行高可调整
|
|
14
|
+
- 列、行可拖拽
|
|
15
|
+
- 虚拟滚动
|
|
16
|
+
- 数据分组
|
|
17
|
+
- 行展开
|
|
18
|
+
- 树嵌套
|
|
19
|
+
- 插件易扩展
|
|
20
|
+
- 多框架支持(Vue、React)
|
|
21
|
+
- 多 UI库支持(Antd、ElementPlus)
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
<details>
|
|
26
|
+
<summary>solid-js</summary>
|
|
27
|
+
|
|
28
|
+
**安装**
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add intable
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**使用**
|
|
35
|
+
|
|
36
|
+
```jsx
|
|
37
|
+
import Intable from 'intable'
|
|
38
|
+
|
|
39
|
+
const App = () => {
|
|
40
|
+
const columns = [
|
|
41
|
+
{ id: 'name', name: '名称' },
|
|
42
|
+
{ id: 'date', name: '日期' },
|
|
43
|
+
{ id: 'address', name: '地址' },
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const data = [
|
|
47
|
+
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
48
|
+
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
49
|
+
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
50
|
+
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
return <Intable data={data} columns={columns} />
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary>vue</summary>
|
|
60
|
+
|
|
61
|
+
**安装**
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
pnpm add @intable/vue
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**使用**
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<template>
|
|
71
|
+
<Intable :data="data" :columns="columns" />
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script setup>
|
|
75
|
+
import Intable from '@intable/vue'
|
|
76
|
+
|
|
77
|
+
const columns = [
|
|
78
|
+
{ id: 'name', name: '名称' },
|
|
79
|
+
{ id: 'date', name: '日期' },
|
|
80
|
+
{ id: 'address', name: '地址' },
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
const data = [
|
|
84
|
+
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
85
|
+
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
86
|
+
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
87
|
+
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
88
|
+
]
|
|
89
|
+
</script>
|
|
90
|
+
```
|
|
91
|
+
</details>
|
|
92
|
+
|
|
93
|
+
<details>
|
|
94
|
+
<summary>react</summary>
|
|
95
|
+
|
|
96
|
+
**安装**
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
pnpm add @intable/react
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**使用**
|
|
103
|
+
|
|
104
|
+
```jsx
|
|
105
|
+
import Intable from '@intable/react'
|
|
106
|
+
|
|
107
|
+
const App = () => {
|
|
108
|
+
const columns = [
|
|
109
|
+
{ id: 'name', name: '名称' },
|
|
110
|
+
{ id: 'date', name: '日期' },
|
|
111
|
+
{ id: 'address', name: '地址' },
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
const data = [
|
|
115
|
+
{ date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
116
|
+
{ date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
117
|
+
{ date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
118
|
+
{ date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
return <Intable data={data} columns={columns} />
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
## Props
|
|
127
|
+
|
|
128
|
+
| 属性名 | 描述 | 类型 | 默认值 |
|
|
129
|
+
| ------------ | ------------ | ------------------------------- | ------- |
|
|
130
|
+
| data | 数据 | any[] | |
|
|
131
|
+
| columns | 展示列 | Column[] | |
|
|
132
|
+
| rowKey | 行唯一键字段 | string | `'id'` |
|
|
133
|
+
| index | 显示序号 | boolean | false |
|
|
134
|
+
| border | 显示纵向边框 | boolean | false |
|
|
135
|
+
| stickyHeader | 表头吸顶 | boolean | false |
|
|
136
|
+
| size | 尺寸 | `'large' \| 'default' \| 'small'` | — |
|
|
137
|
+
| plugins | 插件列表 | Plugin[] | `[]` |
|
|
138
|
+
|
|
139
|
+
## Column
|
|
140
|
+
|
|
141
|
+
| 属性名 | 描述 | 类型 |
|
|
142
|
+
| -------- | ---------------------- | ----------------------------- |
|
|
143
|
+
| id | 字段名,对应数据 key | string \| symbol |
|
|
144
|
+
| name | 表头显示名称 | string |
|
|
145
|
+
| width | 列宽(px) | number |
|
|
146
|
+
| fixed | 固定列 | `'left' \| 'right'` |
|
|
147
|
+
| render | 自定义渲染器 | `string \| Render` |
|
|
148
|
+
| enum | 枚举映射 | `Record<string,any> \| {label?,value}[]` |
|
|
149
|
+
| editable | 是否可编辑 | boolean |
|
|
150
|
+
| editor | 编辑器类型或自定义实现 | `string \| Editor` |
|
|
151
|
+
| resizable| 是否允许调整列宽 | boolean |
|
|
152
|
+
|
|
153
|
+
## 插件
|
|
154
|
+
|
|
155
|
+
插件通过 `plugins` 属性传入,部分插件需从对应路径手动引入。
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### VirtualScrollPlugin — 虚拟滚动
|
|
160
|
+
|
|
161
|
+
大数据量下只渲染可见行列,显著提升性能。
|
|
162
|
+
|
|
163
|
+
```jsx
|
|
164
|
+
import { VirtualScrollPlugin } from 'intable/plugins/VirtualScrollPlugin'
|
|
165
|
+
|
|
166
|
+
<Intable
|
|
167
|
+
plugins={[VirtualScrollPlugin]}
|
|
168
|
+
virtual={{
|
|
169
|
+
y: { estimateSize: () => 40, overscan: 10 }, // 行虚拟化参数
|
|
170
|
+
x: { overscan: 5 }, // 列虚拟化参数
|
|
171
|
+
}}
|
|
172
|
+
/>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### EditablePlugin — 单元格编辑
|
|
178
|
+
|
|
179
|
+
在 Column 上设置 `editable: true` 开启单元格编辑,双击或输入字符进入编辑状态。
|
|
180
|
+
|
|
181
|
+
```jsx
|
|
182
|
+
const columns = [
|
|
183
|
+
{ id: 'name', name: '姓名', editable: true },
|
|
184
|
+
{ id: 'age', name: '年龄', editable: true, editor: 'number' },
|
|
185
|
+
{ id: 'type', name: '类型', editable: true, editor: 'select', enum: { 1: 'A', 2: 'B' } },
|
|
186
|
+
{ id: 'date', name: '日期', editable: true, editor: 'date' },
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
<Intable columns={columns} onDataChange={setData} />
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
内置编辑器类型:`text`(默认)、`number`、`select`、`date`、`time`、`datetime`、`switch`、`checkbox`、`rate`、`color`、`file`。
|
|
193
|
+
|
|
194
|
+
搭配 UI 库插件可直接使用对应组件:
|
|
195
|
+
- **Antd**:`import { AntdPlugin } from '@intable/react/plugins/antd'`
|
|
196
|
+
- **Element Plus**:`import { ElementPlusPlugin } from '@intable/vue/plugins/element-plus'`
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
### RowSelectionPlugin — 行选择
|
|
201
|
+
|
|
202
|
+
```jsx
|
|
203
|
+
<Intable
|
|
204
|
+
rowSelection={{
|
|
205
|
+
enable: true,
|
|
206
|
+
multiple: true, // 多选,默认 true
|
|
207
|
+
value: selectedRows, // 受控选中值
|
|
208
|
+
selectable: row => row.age > 18, // 可选条件
|
|
209
|
+
onChange: rows => setSelected(rows),
|
|
210
|
+
}}
|
|
211
|
+
/>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### ExpandPlugin — 行展开
|
|
217
|
+
|
|
218
|
+
点击行首箭头展开自定义内容区域。
|
|
219
|
+
|
|
220
|
+
```jsx
|
|
221
|
+
<Intable
|
|
222
|
+
expand={{
|
|
223
|
+
enable: true,
|
|
224
|
+
render: ({ data, y }) => <div>详情:{data.name}</div>,
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
### RowGroupPlugin — 行分组
|
|
232
|
+
|
|
233
|
+
按指定字段对行进行分级树形分组,支持展开/折叠。
|
|
234
|
+
|
|
235
|
+
```jsx
|
|
236
|
+
<Intable
|
|
237
|
+
rowGroup={{ fields: ['type', 'subType'] }}
|
|
238
|
+
/>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### TreePlugin — 树形数据
|
|
244
|
+
|
|
245
|
+
渲染嵌套 `children` 字段的树状数据,支持展开/折叠,自动缩进。
|
|
246
|
+
|
|
247
|
+
```jsx
|
|
248
|
+
const data = [
|
|
249
|
+
{ id: 1, name: '总部', children: [
|
|
250
|
+
{ id: 2, name: '研发部' },
|
|
251
|
+
{ id: 3, name: '产品部', children: [
|
|
252
|
+
{ id: 4, name: '设计组' },
|
|
253
|
+
]},
|
|
254
|
+
]},
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
<Intable
|
|
258
|
+
tree={{ children: 'children' }} // 子节点字段名,默认 'children'
|
|
259
|
+
data={data}
|
|
260
|
+
columns={[{ id: 'name', name: '名称' }]}
|
|
261
|
+
/>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
### ResizePlugin — 调整列宽 / 行高
|
|
267
|
+
|
|
268
|
+
拖动表头右侧边框调整列宽,拖动行底部边框调整行高。
|
|
269
|
+
|
|
270
|
+
```jsx
|
|
271
|
+
<Intable
|
|
272
|
+
resizable={{
|
|
273
|
+
col: { enable: true, min: 60, max: 600 },
|
|
274
|
+
row: { enable: true, min: 28, max: 200 },
|
|
275
|
+
}}
|
|
276
|
+
onColumnsChange={cols => setColumns(cols)}
|
|
277
|
+
/>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
也可在单列上单独控制:
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
{ id: 'name', name: '姓名', resizable: false } // 禁止该列拖拽
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
### DragPlugin — 列 / 行拖拽排序
|
|
289
|
+
|
|
290
|
+
长按后拖拽列标题或行首单元格可重新排序。
|
|
291
|
+
|
|
292
|
+
```jsx
|
|
293
|
+
<Intable
|
|
294
|
+
colDrag={true} // 开启列拖拽
|
|
295
|
+
rowDrag={true} // 开启行拖拽
|
|
296
|
+
onColumnsChange={cols => setColumns(cols)}
|
|
297
|
+
/>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
### HistoryPlugin — 撤销 / 重做
|
|
303
|
+
|
|
304
|
+
记录数据变更历史,支持 `Ctrl+Z` / `Ctrl+Y`。
|
|
305
|
+
|
|
306
|
+
```jsx
|
|
307
|
+
import { HistoryPlugin } from 'intable/plugins/HistoryPlugin'
|
|
308
|
+
|
|
309
|
+
<Intable plugins={[HistoryPlugin]} />
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
通过命令调用:
|
|
313
|
+
```js
|
|
314
|
+
store.history.undo()
|
|
315
|
+
store.history.redo()
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
### DiffPlugin — 数据差异对比
|
|
321
|
+
|
|
322
|
+
将当前数据与快照进行比较,高亮新增/删除/修改行,支持提交。
|
|
323
|
+
|
|
324
|
+
```jsx
|
|
325
|
+
import { DiffPlugin } from 'intable/plugins/DiffPlugin'
|
|
326
|
+
|
|
327
|
+
<Intable
|
|
328
|
+
plugins={[DiffPlugin]}
|
|
329
|
+
diff={{
|
|
330
|
+
added: true, // 高亮新增行,默认 true
|
|
331
|
+
removed: true, // 高亮删除行,默认 true
|
|
332
|
+
changed: true, // 高亮修改行,默认 true
|
|
333
|
+
onCommit: (data, { added, removed, changed }) => save(data),
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
`Ctrl+S` 触发提交,或通过命令:
|
|
339
|
+
```js
|
|
340
|
+
store.commands.diffCommit()
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### CellMergePlugin — 单元格合并
|
|
346
|
+
|
|
347
|
+
通过 `merge` 回调或 Column 的 `mergeRow` 快捷属性合并相邻单元格。
|
|
348
|
+
|
|
349
|
+
```jsx
|
|
350
|
+
// 方式一:全局 merge 回调
|
|
351
|
+
<Intable
|
|
352
|
+
merge={(row, col, y, x) => {
|
|
353
|
+
if (col.id === 'name') {
|
|
354
|
+
let rowspan = 1
|
|
355
|
+
while (data[y + rowspan]?.name === row.name) rowspan++
|
|
356
|
+
return rowspan > 1 ? { rowspan } : null
|
|
357
|
+
}
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
|
|
361
|
+
// 方式二:列级 mergeRow 快捷属性(自动合并相邻等值行)
|
|
362
|
+
const columns = [
|
|
363
|
+
{ id: 'type', name: '类型', mergeRow: true },
|
|
364
|
+
{ id: 'name', name: '名称' },
|
|
365
|
+
]
|
|
366
|
+
<Intable columns={columns} />
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
### CellSelectionPlugin — 单元格多选
|
|
372
|
+
|
|
373
|
+
鼠标拖拽或 `Shift+点击` 选择矩形区域,箭头键移动焦点。
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
### CopyPastePlugin — 复制粘贴
|
|
378
|
+
|
|
379
379
|
`Ctrl+C` 复制选中区域为 TSV 格式,`Ctrl+V` 粘贴。
|