stk-table-vue 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -8,15 +8,17 @@ repo:
8
8
  - [Github](https://github.com/ja-plus/stk-table-vue)
9
9
  - [Gitee](https://gitee.com/japlus/stk-table-vue) 🇨🇳
10
10
 
11
+ [<span style="font-size: 16px;font-weight: bold;">Online Demo</span>](https://stackblitz.com/edit/vitejs-vite-ad91hh?file=src%2FDemo%2Findex.vue)
12
+
11
13
  ## Bug TODO:
12
14
  * [x] props.dataSource 为 shallowRef 时,高亮行不生效。(bug:2024.02.21)(resolved:0.2.3)
15
+ * [] 固定列列宽拖动目标。
13
16
 
14
17
  ## Feature TODO:
15
- * [x] 高亮行,单元格。使用css @keyframes实现。
16
- - [x] 虚拟滚动默认通过js计算行高亮背景色,可通过 `useCss` 设置为css @keyframe实现 。
17
- - [x] 支持配置高亮参数(持续时间,颜色,频率(虚拟滚动))。(`v0.2.9`)
18
- - [x] `setHighlightDimRow`/`setHighlightCellRow`支持自定义高亮css类名。(`v0.2.9`)
18
+ * [x] 高亮行,单元格。
19
19
  - [x] 使用 `Web Animations API` 实现高亮。(`v0.3.4` 变更为默认值)
20
+ - [x] 支持配置高亮参数(持续时间,颜色,频率)。(`v0.2.9`)
21
+ - [x] `setHighlightDimRow`/`setHighlightCellRow`支持自定义高亮css类名。(`v0.2.9`)
20
22
  * [x] 虚拟滚动。
21
23
  - [x] 纵向。
22
24
  - [x] 横向(必须设置列宽)。
@@ -26,21 +28,16 @@ repo:
26
28
  - [x] sticky column 动态计算阴影位置。(`v0.4.0`)
27
29
  * [] 列筛选。
28
30
  * [x] 斑马纹。
29
- - [x] 虚拟滚动斑马纹。
30
- * [x] 表头拖动更改顺序。
31
- * [x] 表头拖动调整列宽。
31
+ * [x] 拖动更改列顺序。
32
+ * [x] 拖动调整列宽。
32
33
  * [x] 排序
33
- - [x] 基本表头点击排序。
34
34
  - [x] 支持配置 `null` | `undefined` 永远排最后。
35
35
  - [x] 支持配置 string 使用 `String.prototype.localCompare` 排序。
36
36
  * [x] 多级表头。
37
- - [x] 支持最多`2级`表头。
38
- - [x] 支持更多级表头。
39
37
  - [] 横向虚拟滚动。
40
38
  * [x] 支持table-layout: fixed 配置。
41
39
  * [x] 鼠标悬浮在表格上,键盘滚动虚拟表格。
42
- - [x] 键盘 `ArrowUp`/`ArrowDown`/`ArrowLeft`/`ArrowRight` 按键支持。
43
- - [x] 键盘 `PageUp`/ `PageDown` 按键支持。
40
+ - [x] 键盘 `ArrowUp`/`ArrowDown`/`ArrowLeft`/`ArrowRight`/`PageUp`/ `PageDown` 按键支持。
44
41
  * [] 非虚拟滚动时,大数据分批加载。
45
42
  * [x] vue2.7支持(引入源码使用)。
46
43
  - [x] `props.optimizeVue2Scroll` 优化vue2虚拟滚动流畅度。(`v0.2.0`)
@@ -48,8 +45,6 @@ repo:
48
45
  * [x] `props.cellHover`单元格悬浮样式。(`v0.3.2`)
49
46
 
50
47
 
51
-
52
-
53
48
  ## Usage
54
49
  > npm install stk-table-vue
55
50
 
@@ -61,15 +56,15 @@ const stkTable = ref<InstanceType<typeof StkTable>>();
61
56
 
62
57
  // highlight row
63
58
  stkTable.value.setHighlightDimRow([rowKey],{
64
- method: 'css'|'js'|'animation',// 是否使用css @keyframe实现。虚拟滚动下默认false
65
- className: 'custom-class-name',// useCss 为true时生效。
59
+ method: 'css'|'js'|'animation',// 默认 animation
60
+ className: 'custom-class-name', // method css 时生效。
66
61
  keyframe: [{backgroundColor:'#aaa'},{backgroundColor: '#222'}],//same as https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
67
62
  duration: 2000,// 动画时长。
68
63
  });
69
64
  // highlight cell
70
65
  stkTable.value.setHighlightDimCell(rowKey, colDataIndex, {
71
66
  method: 'css'|'animation',
72
- className:'custom-class-name',// method css 时生效。
67
+ className:'custom-class-name', // method css 时生效。
73
68
  keyframe: [{backgroundColor:'#aaa'},{backgroundColor: '#222'}], // method animation 时生效。
74
69
  duration: 2000,// 动画时长。
75
70
  })
@@ -85,10 +80,10 @@ stkTable.value.setHighlightDimCell(rowKey, colDataIndex, {
85
80
  vue2.7 支持引入源码使用。依赖`less`。
86
81
  ```html
87
82
  <script>
88
- import { StkTable } from 'stk-table-vue/src/StkTable/index';
83
+ import { StkTable } from 'stk-table-vue/src/StkTable/index'; // include less
89
84
  </script>
90
85
  ```
91
- 不要less的话
86
+ Use `css`
92
87
  ```html
93
88
  <script>
94
89
  import { StkTable } from 'stk-table-vue/src/StkTable/StkTable.vue';
@@ -149,7 +144,7 @@ export type StkProps = {
149
144
  columns?: StkTableColumn<any>[];
150
145
  /** 表格数据源 */
151
146
  dataSource?: any[];
152
- /** 行唯一键 */
147
+ /** 行唯一键 (行唯一值不能为undefined)*/
153
148
  rowKey?: UniqKeyProp;
154
149
  /** 列唯一键 */
155
150
  colKey?: UniqKeyProp;
@@ -217,7 +212,7 @@ export type StkProps = {
217
212
  */
218
213
  stringLocaleCompare?: boolean;
219
214
  },
220
- /** 隐藏头部title。可传入dataIndex数组 */
215
+ /** 隐藏头部鼠标悬浮title。可传入dataIndex数组 */
221
216
  hideHeaderTitle?: boolean | string[];
222
217
  /** 高亮配置 */
223
218
  highlightConfig?: {
@@ -232,8 +227,8 @@ export type StkProps = {
232
227
  startIndex?: number;
233
228
  };
234
229
  /**
235
- * 固定头,固定列实现方式。(非响应式)
236
- *
230
+ * 固定头,固定列实现方式。
231
+ * [非响应式]
237
232
  * relative:固定列只能放在props.columns的两侧。
238
233
  * - 如果列宽会变动则谨慎使用。
239
234
  * - 多级表头固定列慎用
@@ -259,9 +254,9 @@ export type StkProps = {
259
254
  (e: 'row-click', ev: MouseEvent, row: DT): void;
260
255
  /**
261
256
  * 选中一行触发。ev返回null表示不是点击事件触发的
262
- * ```(ev: MouseEvent | null, row: DT, data: { select: boolean })```
257
+ * ```(ev: MouseEvent | null, row: DT | undefined,, data: { select: boolean })```
263
258
  */
264
- (e: 'current-change', ev: MouseEvent | null, row: DT, data: { select: boolean }): void;
259
+ (e: 'current-change', ev: MouseEvent | null, row: DT | undefined,, data: { select: boolean }): void;
265
260
  /**
266
261
  * 行双击事件
267
262
  * ```(ev: MouseEvent, row: DT)```
@@ -428,7 +423,7 @@ export type SortConfig<T extends Record<string, any>> = {
428
423
  };
429
424
  /**
430
425
  * string排序是否使用 String.prototype.localCompare
431
- * 默认true (&$&应该false)
426
+ * 默认true ($*$应该false)
432
427
  */
433
428
  stringLocaleCompare?: boolean;
434
429
  };
@@ -464,20 +459,20 @@ export type SortConfig<T extends Record<string, any>> = {
464
459
  )
465
460
  ```
466
461
  #### option
467
- | key |value| desc |
468
- | ---- | ---- | ---- |
469
- | method | `css` `animation` `js` | 设置高亮方式。虚拟滚动默认js。否则css |
470
- | ~~useCss~~ `deprecated` | `boolean`| ~~是否使用css~~ |
471
- | className | `string` | 设置高亮样式。method == 'css' 生效 |
472
- | keyframe | `Parameters<Animatable['animate']>['0']` | 设置高亮动画。method == 'animation' 生效。 |
473
- | duration | `number` | 设置高亮动画持续时间。 method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。|
462
+ | key |value| default |desc |
463
+ | ---- | ---- | ---- | ---- |
464
+ | method | `css` `animation` `js` | `animation` | 设置高亮方式。 |
465
+ | ~~useCss~~ `deprecated` | `boolean`| false | ~~是否使用css~~ |
466
+ | className | `string` | `highlight-row`/`highlight-cell` | 自定义 css 动画。method == 'css' 生效 |
467
+ | keyframe | `Parameters<Animatable['animate']>['0']` | ... | 自定义高亮动画。method == 'animation' 生效。 |
468
+ | duration | `number` | 2000 | 设置高亮动画持续时间ms。 method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。|
474
469
 
475
470
  ##### option.method
476
471
  | `option.method`| desc |
477
472
  | ---- | ---- |
478
- | css | 使用css class 实现高亮。 |
479
- | animation | 使用 animation api 实现高亮。 |
480
- | js | 使用 js 循环计算颜色实现高亮。虚拟滚动默认使用js。 |
473
+ | animation | animation api 实现高亮。(default) |
474
+ | css | css @keyframes 实现高亮。 |
475
+ | js | js 循环计算颜色实现高亮。 |
481
476
 
482
477
  ### Example
483
478
  ```vue
@@ -539,7 +534,7 @@ export type SortConfig<T extends Record<string, any>> = {
539
534
  customCell: defineComponent({
540
535
  setup(){
541
536
  //...
542
- return () => <div></div>
537
+ return () => <div></div> // vue jsx
543
538
  }
544
539
  })
545
540
  },
@@ -567,6 +562,11 @@ export type SortConfig<T extends Record<string, any>> = {
567
562
  - 在 `customCell` 较多且复杂时。
568
563
  - 大量 highlight 动画时。
569
564
 
565
+ ## Tips
566
+ ### props.fixedMode
567
+ * **低版本浏览器** 需要设置 `props.width`(default: width=fit-content不生效)。否则列宽不设宽度会变为0。
568
+
569
+
570
570
  ## Other
571
571
  * `$*$` 兼容注释
572
572
 
@@ -1,6 +1,7 @@
1
1
  import { HighlightConfig, Order, SeqConfig, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
2
+
2
3
  /** Generic stands for DataType */
3
- type DT = any;
4
+ type DT = Record<string | number, any>;
4
5
  /**
5
6
  * 选中一行,
6
7
  * @param {string} rowKey selected rowKey, null to unselect
@@ -23,7 +24,7 @@ declare function setSorter(dataIndex: string, order: Order, option?: {
23
24
  force?: boolean;
24
25
  silent?: boolean;
25
26
  sort?: boolean;
26
- }): any[];
27
+ }): DT[];
27
28
  /** 重置排序 */
28
29
  declare function resetSorter(): void;
29
30
  /**
@@ -33,10 +34,10 @@ declare function resetSorter(): void;
33
34
  */
34
35
  declare function scrollTo(top?: number | null, left?: number | null): void;
35
36
  /** 获取当前状态的表格数据 */
36
- declare function getTableData(): any[];
37
+ declare function getTableData(): DT[];
37
38
  /** 获取当前排序列的信息 */
38
- declare function getSortColumns(): SortState<DT>[];
39
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
39
+ declare function getSortColumns(): Partial<SortState<DT>>[];
40
+ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
40
41
  width?: string | undefined;
41
42
  /** 最小表格宽度 */
42
43
  minWidth?: string | undefined;
@@ -44,7 +45,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
44
45
  maxWidth?: string | undefined;
45
46
  /** 斑马线条纹 */
46
47
  stripe?: boolean | undefined;
47
- /** 是否使用 table-layout:fixed */
48
+ /** 是否使用 table-layout:fixed(低版本浏览器需要设置table) */
48
49
  fixedMode?: boolean | undefined;
49
50
  /** 是否隐藏表头 */
50
51
  headless?: boolean | undefined;
@@ -59,17 +60,17 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
59
60
  /** x轴虚拟滚动(必须设置列宽)*/
60
61
  virtualX?: boolean | undefined;
61
62
  /** 表格列配置 */
62
- columns?: StkTableColumn<any>[] | undefined;
63
+ columns?: StkTableColumn<DT>[] | undefined;
63
64
  /** 表格数据源 */
64
- dataSource?: any[] | undefined;
65
- /** 行唯一键 */
65
+ dataSource?: DT[] | undefined;
66
+ /** 行唯一键 (行唯一值不能为undefined) */
66
67
  rowKey?: UniqKeyProp | undefined;
67
68
  /** 列唯一键 */
68
69
  colKey?: UniqKeyProp | undefined;
69
70
  /** 空值展示文字 */
70
71
  emptyCellText?: string | ((option: {
71
- row: any;
72
- col: StkTableColumn<any>;
72
+ row: DT;
73
+ col: StkTableColumn<DT>;
73
74
  }) => string) | undefined;
74
75
  /** 暂无数据兜底高度是否撑满 */
75
76
  noDataFull?: boolean | undefined;
@@ -86,12 +87,12 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
86
87
  /** 是否高亮鼠标悬浮的单元格 */
87
88
  cellHover?: boolean | undefined;
88
89
  /** 表头是否可拖动。支持回调函数。 */
89
- headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
90
+ headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean) | undefined;
90
91
  /**
91
92
  * 给行附加className<br>
92
93
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
93
94
  */
94
- rowClassName?: ((row: any, i: number) => string) | undefined;
95
+ rowClassName?: ((row: DT, i: number) => string) | undefined;
95
96
  /**
96
97
  * 列宽是否可拖动<br>
97
98
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -119,7 +120,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
119
120
  /** 优化vue2 滚动 */
120
121
  optimizeVue2Scroll?: boolean | undefined;
121
122
  /** 排序配置 */
122
- sortConfig?: SortConfig<any> | undefined;
123
+ sortConfig?: SortConfig<DT> | undefined;
123
124
  /** 隐藏头部title。可传入dataIndex数组 */
124
125
  hideHeaderTitle?: boolean | string[] | undefined;
125
126
  /** 高亮配置 */
@@ -189,11 +190,14 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
189
190
  setHighlightDimCell: (rowKeyValue: string, dataIndex: string, option?: {
190
191
  className?: string | undefined;
191
192
  method?: "animation" | "css" | undefined;
192
- keyframe?: Keyframe[] | PropertyIndexedKeyframes | null | undefined;
193
+ keyframe?: Keyframe[] | PropertyIndexedKeyframes | null | undefined; /**
194
+ * 选中一行触发。ev返回null表示不是点击事件触发的
195
+ * ```(ev: MouseEvent | null, row: DT | undefined, data: { select: boolean })```
196
+ */
193
197
  duration?: number | undefined;
194
198
  }) => void;
195
199
  /** 设置高亮渐暗行 */
196
- setHighlightDimRow: (rowKeyValues: import("./types/index").UniqKey[], option?: {
200
+ setHighlightDimRow: (rowKeyValues: import('./types/index').UniqKey[], option?: {
197
201
  method?: "animation" | "css" | "js" | undefined;
198
202
  useCss?: boolean | undefined;
199
203
  className?: string | undefined;
@@ -201,7 +205,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
201
205
  duration?: number | undefined;
202
206
  }) => void;
203
207
  /** 表格排序列dataIndex */
204
- sortCol: import("vue").Ref<string | null | undefined>;
208
+ sortCol: import('vue').Ref<string | number | undefined>;
205
209
  /** 获取当前排序状态 */
206
210
  getSortColumns: typeof getSortColumns;
207
211
  /** 设置排序 */
@@ -212,20 +216,20 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
212
216
  scrollTo: typeof scrollTo;
213
217
  /** 获取表格数据 */
214
218
  getTableData: typeof getTableData;
215
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
216
- "sort-change": (col: StkTableColumn<any>, order: Order, data: any[], sortConfig: SortConfig<any>) => void;
217
- "row-click": (ev: MouseEvent, row: any) => void;
218
- "current-change": (ev: MouseEvent | null, row: any, data: {
219
+ }, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
220
+ "sort-change": (col: StkTableColumn<DT>, order: Order, data: DT[], sortConfig: SortConfig<DT>) => void;
221
+ "row-click": (ev: MouseEvent, row: DT) => void;
222
+ "current-change": (ev: MouseEvent | null, row: DT | undefined, data: {
219
223
  select: boolean;
220
224
  }) => void;
221
- "row-dblclick": (ev: MouseEvent, row: any) => void;
225
+ "row-dblclick": (ev: MouseEvent, row: DT) => void;
222
226
  "header-row-menu": (ev: MouseEvent) => void;
223
- "row-menu": (ev: MouseEvent, row: any) => void;
224
- "cell-click": (ev: MouseEvent, row: any, col: StkTableColumn<any>) => void;
225
- "cell-mouseenter": (ev: MouseEvent, row: any, col: StkTableColumn<any>) => void;
226
- "cell-mouseleave": (ev: MouseEvent, row: any, col: StkTableColumn<any>) => void;
227
- "cell-mouseover": (ev: MouseEvent, row: any, col: StkTableColumn<any>) => void;
228
- "header-cell-click": (ev: MouseEvent, col: StkTableColumn<any>) => void;
227
+ "row-menu": (ev: MouseEvent, row: DT) => void;
228
+ "cell-click": (ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => void;
229
+ "cell-mouseenter": (ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => void;
230
+ "cell-mouseleave": (ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => void;
231
+ "cell-mouseover": (ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => void;
232
+ "header-cell-click": (ev: MouseEvent, col: StkTableColumn<DT>) => void;
229
233
  scroll: (ev: Event, data: {
230
234
  startIndex: number;
231
235
  endIndex: number;
@@ -234,8 +238,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
234
238
  "col-order-change": (dragStartKey: string, targetColKey: string) => void;
235
239
  "th-drag-start": (dragStartKey: string) => void;
236
240
  "th-drop": (targetColKey: string) => void;
237
- "update:columns": (cols: StkTableColumn<any>[]) => void;
238
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
241
+ "update:columns": (cols: StkTableColumn<DT>[]) => void;
242
+ }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
239
243
  width?: string | undefined;
240
244
  /** 最小表格宽度 */
241
245
  minWidth?: string | undefined;
@@ -243,7 +247,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
243
247
  maxWidth?: string | undefined;
244
248
  /** 斑马线条纹 */
245
249
  stripe?: boolean | undefined;
246
- /** 是否使用 table-layout:fixed */
250
+ /** 是否使用 table-layout:fixed(低版本浏览器需要设置table) */
247
251
  fixedMode?: boolean | undefined;
248
252
  /** 是否隐藏表头 */
249
253
  headless?: boolean | undefined;
@@ -258,17 +262,17 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
258
262
  /** x轴虚拟滚动(必须设置列宽)*/
259
263
  virtualX?: boolean | undefined;
260
264
  /** 表格列配置 */
261
- columns?: StkTableColumn<any>[] | undefined;
265
+ columns?: StkTableColumn<DT>[] | undefined;
262
266
  /** 表格数据源 */
263
- dataSource?: any[] | undefined;
264
- /** 行唯一键 */
267
+ dataSource?: DT[] | undefined;
268
+ /** 行唯一键 (行唯一值不能为undefined) */
265
269
  rowKey?: UniqKeyProp | undefined;
266
270
  /** 列唯一键 */
267
271
  colKey?: UniqKeyProp | undefined;
268
272
  /** 空值展示文字 */
269
273
  emptyCellText?: string | ((option: {
270
- row: any;
271
- col: StkTableColumn<any>;
274
+ row: DT;
275
+ col: StkTableColumn<DT>;
272
276
  }) => string) | undefined;
273
277
  /** 暂无数据兜底高度是否撑满 */
274
278
  noDataFull?: boolean | undefined;
@@ -285,12 +289,12 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
285
289
  /** 是否高亮鼠标悬浮的单元格 */
286
290
  cellHover?: boolean | undefined;
287
291
  /** 表头是否可拖动。支持回调函数。 */
288
- headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
292
+ headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean) | undefined;
289
293
  /**
290
294
  * 给行附加className<br>
291
295
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
292
296
  */
293
- rowClassName?: ((row: any, i: number) => string) | undefined;
297
+ rowClassName?: ((row: DT, i: number) => string) | undefined;
294
298
  /**
295
299
  * 列宽是否可拖动<br>
296
300
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -318,7 +322,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
318
322
  /** 优化vue2 滚动 */
319
323
  optimizeVue2Scroll?: boolean | undefined;
320
324
  /** 排序配置 */
321
- sortConfig?: SortConfig<any> | undefined;
325
+ sortConfig?: SortConfig<DT> | undefined;
322
326
  /** 隐藏头部title。可传入dataIndex数组 */
323
327
  hideHeaderTitle?: boolean | string[] | undefined;
324
328
  /** 高亮配置 */
@@ -380,43 +384,43 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
380
384
  startIndex: number;
381
385
  endIndex: number;
382
386
  }) => any) | undefined;
383
- "onUpdate:columns"?: ((cols: StkTableColumn<any>[]) => any) | undefined;
387
+ "onUpdate:columns"?: ((cols: StkTableColumn<DT>[]) => any) | undefined;
384
388
  "onTh-drag-start"?: ((dragStartKey: string) => any) | undefined;
385
389
  "onCol-order-change"?: ((dragStartKey: string, targetColKey: string) => any) | undefined;
386
390
  "onTh-drop"?: ((targetColKey: string) => any) | undefined;
387
- "onSort-change"?: ((col: StkTableColumn<any>, order: Order, data: any[], sortConfig: SortConfig<any>) => any) | undefined;
388
- "onRow-click"?: ((ev: MouseEvent, row: any) => any) | undefined;
389
- "onCurrent-change"?: ((ev: MouseEvent | null, row: any, data: {
391
+ "onSort-change"?: ((col: StkTableColumn<DT>, order: Order, data: DT[], sortConfig: SortConfig<DT>) => any) | undefined;
392
+ "onRow-click"?: ((ev: MouseEvent, row: DT) => any) | undefined;
393
+ "onCurrent-change"?: ((ev: MouseEvent | null, row: DT | undefined, data: {
390
394
  select: boolean;
391
395
  }) => any) | undefined;
392
- "onRow-dblclick"?: ((ev: MouseEvent, row: any) => any) | undefined;
396
+ "onRow-dblclick"?: ((ev: MouseEvent, row: DT) => any) | undefined;
393
397
  "onHeader-row-menu"?: ((ev: MouseEvent) => any) | undefined;
394
- "onRow-menu"?: ((ev: MouseEvent, row: any) => any) | undefined;
395
- "onCell-click"?: ((ev: MouseEvent, row: any, col: StkTableColumn<any>) => any) | undefined;
396
- "onCell-mouseenter"?: ((ev: MouseEvent, row: any, col: StkTableColumn<any>) => any) | undefined;
397
- "onCell-mouseleave"?: ((ev: MouseEvent, row: any, col: StkTableColumn<any>) => any) | undefined;
398
- "onCell-mouseover"?: ((ev: MouseEvent, row: any, col: StkTableColumn<any>) => any) | undefined;
399
- "onHeader-cell-click"?: ((ev: MouseEvent, col: StkTableColumn<any>) => any) | undefined;
398
+ "onRow-menu"?: ((ev: MouseEvent, row: DT) => any) | undefined;
399
+ "onCell-click"?: ((ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => any) | undefined;
400
+ "onCell-mouseenter"?: ((ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => any) | undefined;
401
+ "onCell-mouseleave"?: ((ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => any) | undefined;
402
+ "onCell-mouseover"?: ((ev: MouseEvent, row: DT, col: StkTableColumn<DT>) => any) | undefined;
403
+ "onHeader-cell-click"?: ((ev: MouseEvent, col: StkTableColumn<DT>) => any) | undefined;
400
404
  "onScroll-x"?: ((ev: Event) => any) | undefined;
401
405
  }, {
402
406
  width: string;
403
407
  minWidth: string;
404
408
  maxWidth: string;
405
409
  rowHeight: number;
406
- headless: boolean;
407
410
  headerRowHeight: number | null;
411
+ headless: boolean;
408
412
  stripe: boolean;
409
413
  fixedMode: boolean;
410
414
  theme: "light" | "dark";
411
415
  virtual: boolean;
412
416
  virtualX: boolean;
413
- columns: StkTableColumn<any>[];
414
- dataSource: any[];
417
+ columns: StkTableColumn<DT>[];
418
+ dataSource: DT[];
415
419
  rowKey: UniqKeyProp;
416
420
  colKey: UniqKeyProp;
417
421
  emptyCellText: string | ((option: {
418
- row: any;
419
- col: StkTableColumn<any>;
422
+ row: DT;
423
+ col: StkTableColumn<DT>;
420
424
  }) => string);
421
425
  noDataFull: boolean;
422
426
  showNoData: boolean;
@@ -425,22 +429,22 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
425
429
  showOverflow: boolean;
426
430
  showTrHoverClass: boolean;
427
431
  cellHover: boolean;
428
- headerDrag: boolean | ((col: StkTableColumn<any>) => boolean);
429
- rowClassName: (row: any, i: number) => string;
432
+ headerDrag: boolean | ((col: StkTableColumn<DT>) => boolean);
433
+ rowClassName: (row: DT, i: number) => string;
430
434
  colResizable: boolean;
431
435
  colMinWidth: number;
432
436
  bordered: boolean | "h" | "v" | "body-v";
433
437
  autoResize: boolean | (() => void);
434
438
  fixedColShadow: boolean;
435
439
  optimizeVue2Scroll: boolean;
436
- sortConfig: SortConfig<any>;
440
+ sortConfig: SortConfig<DT>;
437
441
  hideHeaderTitle: boolean | string[];
438
442
  highlightConfig: HighlightConfig;
439
443
  seqConfig: SeqConfig;
440
444
  cellFixedMode: "sticky" | "relative";
441
445
  }, {}>, {
442
446
  tableHeader?(_: {
443
- col: StkTableColumn<any>;
447
+ col: StkTableColumn<DT>;
444
448
  }): any;
445
449
  empty?(_: {}): any;
446
450
  }>;
@@ -21,6 +21,6 @@ export declare const HIGHLIGHT_FREQ: number;
21
21
  export declare const HIGHLIGHT_ROW_CLASS = "highlight-row";
22
22
  /** 高连单元格class */
23
23
  export declare const HIGHLIGHT_CELL_CLASS = "highlight-cell";
24
- /** 是否兼容低版本模式 */
24
+ /** 低版本sticky兼容模式 */
25
25
  export declare const IS_LEGACY_MODE: boolean;
26
26
  export declare const STK_ID_PREFIX = "stk";
@@ -1,4 +1,3 @@
1
1
  export { default as StkTable } from './StkTable.vue';
2
2
  export { tableSort, insertToOrderedArray } from './utils';
3
3
  export type { StkTableColumn } from './types/index';
4
- import './style.less';
@@ -1,21 +1,34 @@
1
1
  import { Component, VNode } from 'vue';
2
+
2
3
  /** 排序方式,asc-正序,desc-倒序,null-默认顺序 */
3
4
  export type Order = null | 'asc' | 'desc';
4
5
  type Sorter<T> = boolean | ((data: T[], option: {
5
6
  order: Order;
6
7
  column: any;
7
8
  }) => T[]);
8
- export type CustomCellFunc<T extends Record<string, any>> = (props: {
9
+ export type CustomCellProps<T extends Record<string, any>> = {
9
10
  row: T;
10
11
  col: StkTableColumn<T>;
11
12
  /** row[col.dataIndex] 的值 */
12
13
  cellValue: any;
13
14
  rowIndex: number;
14
15
  colIndex: number;
15
- }) => VNode;
16
- export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: {
16
+ };
17
+ /**
18
+ * $*$自定义单元格渲染函数
19
+ * @deprecated
20
+ */
21
+ export type CustomCellFunc<T extends Record<string, any>> = (props: CustomCellProps<T>) => VNode;
22
+ export type CustomHeaderCellProps<T extends Record<string, any>> = {
17
23
  col: StkTableColumn<T>;
18
- }) => VNode;
24
+ rowIndex: number;
25
+ colIndex: number;
26
+ };
27
+ /**
28
+ * $*$自定义表头渲染函数
29
+ * @deprecated
30
+ */
31
+ export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: CustomHeaderCellProps<T>) => VNode;
19
32
  /** 表格列配置 */
20
33
  export type StkTableColumn<T extends Record<string, any>> = {
21
34
  /**
@@ -55,17 +68,22 @@ export type StkTableColumn<T extends Record<string, any>> = {
55
68
  * 自定义 td 渲染内容。
56
69
  *
57
70
  * 组件prop入参:
58
- * - props.row 一行的记录。
59
- * - props.col 列配置
71
+ * @param props.row 一行的记录。
72
+ * @param props.col 列配置
73
+ * @param props.cellValue row[col.dataIndex] 的值
74
+ * @param props.rowIndex 行索引
75
+ * @param props.colIndex 列索引
60
76
  */
61
- customCell?: Component | VNode | CustomCellFunc<T>;
77
+ customCell?: Component<CustomCellProps<T>> | string;
62
78
  /**
63
79
  * 自定义 th 渲染内容
64
80
  *
65
81
  * 组件prop入参:
66
- * - props.col 列配置
82
+ * @param props.col 列配置
83
+ * @param props.rowIndex 行索引
84
+ * @param props.colIndex 列索引
67
85
  */
68
- customHeaderCell?: Component | VNode | CustomHeaderCellFunc<T>;
86
+ customHeaderCell?: Component<CustomHeaderCellProps<T>> | string;
69
87
  /** 二级表头 */
70
88
  children?: StkTableColumn<T>[];
71
89
  /** 父节点引用 */
@@ -76,7 +94,7 @@ export type StkTableColumn<T extends Record<string, any>> = {
76
94
  export type SortOption<T extends Record<string, any>> = Pick<StkTableColumn<T>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
77
95
  /** 排序状态 */
78
96
  export type SortState<T> = {
79
- dataIndex: T;
97
+ dataIndex: keyof T;
80
98
  order: null | 'asc' | 'desc';
81
99
  sortType?: 'number' | 'string';
82
100
  };
@@ -100,7 +118,7 @@ export type SortConfig<T extends Record<string, any>> = {
100
118
  };
101
119
  /**
102
120
  * string排序是否使用 String.prototype.localCompare
103
- * 默认true (&$&应该false)
121
+ * 默认true ($*$应该false)
104
122
  */
105
123
  stringLocaleCompare?: boolean;
106
124
  };
@@ -1,4 +1,5 @@
1
1
  import { Ref } from 'vue';
2
+
2
3
  type Options = {
3
4
  props: any;
4
5
  tableContainerRef: Ref<HTMLElement | undefined>;
@@ -1,5 +1,6 @@
1
1
  import { ComputedRef, Ref, ShallowRef } from 'vue';
2
2
  import { StkTableColumn, UniqKey } from './types';
3
+
3
4
  type Params<DT extends Record<string, any>> = {
4
5
  props: any;
5
6
  emits: any;
@@ -1,6 +1,7 @@
1
1
  import { ComputedRef, Ref, ShallowRef } from 'vue';
2
2
  import { StkTableColumn, UniqKey } from './types';
3
3
  import { VirtualScrollXStore } from './useVirtualScroll';
4
+
4
5
  type Params<T extends Record<string, any>> = {
5
6
  props: any;
6
7
  colKeyGen: ComputedRef<(col: StkTableColumn<T>) => UniqKey>;
@@ -1,6 +1,7 @@
1
1
  import { CSSProperties, ComputedRef, Ref } from 'vue';
2
2
  import { StkTableColumn, TagType } from './types';
3
3
  import { VirtualScrollStore, VirtualScrollXStore } from './useVirtualScroll';
4
+
4
5
  type Options<T extends Record<string, any>> = {
5
6
  props: any;
6
7
  isRelativeMode: Ref<boolean>;
@@ -1,5 +1,6 @@
1
1
  import { ComputedRef, ShallowRef } from 'vue';
2
2
  import { StkTableColumn, UniqKey } from './types';
3
+
3
4
  type Params<T extends Record<string, any>> = {
4
5
  colKeyGen: ComputedRef<(col: StkTableColumn<T>) => UniqKey>;
5
6
  tableHeaders: ShallowRef<StkTableColumn<T>[][]>;
@@ -1,5 +1,6 @@
1
1
  import { Ref } from 'vue';
2
2
  import { UniqKey } from './types';
3
+
3
4
  type Params = {
4
5
  props: any;
5
6
  stkTableId: string;
@@ -1,6 +1,7 @@
1
1
  import { ComputedRef, Ref, ShallowRef } from 'vue';
2
2
  import { StkTableColumn } from './types';
3
3
  import { VirtualScrollStore, VirtualScrollXStore } from './useVirtualScroll';
4
+
4
5
  type Options<DT extends Record<string, any>> = {
5
6
  props: any;
6
7
  scrollTo: (y: number | null, x: number | null) => void;
@@ -1,4 +1,5 @@
1
1
  import { StkTableColumn } from './types';
2
+
2
3
  type Params = {
3
4
  props: any;
4
5
  emits: any;