stk-table-vue 0.2.5 → 0.2.6

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
@@ -40,7 +40,8 @@ repo:
40
40
  * [] 非虚拟滚动时,大数据分批加载。
41
41
  * [x] vue2.7支持(引入源码使用)。
42
42
  - [x] `props.optimizeVue2Scroll` 优化vue2虚拟滚动流畅度。
43
- * [] `props.emptyCellText` 支持传入函数。
43
+ * [x] `props.emptyCellText` 支持传入函数。
44
+ * [] 支持配置高亮参数。
44
45
 
45
46
 
46
47
  ## Usage
@@ -135,7 +136,7 @@ export type StkProps = {
135
136
  /** 列唯一键 */
136
137
  colKey?: UniqKeyProp;
137
138
  /** 空值展示文字 */
138
- emptyCellText?: string;
139
+ emptyCellText?: string | ((option: { row: DT; col: StkTableColumn<DT> }) => string);
139
140
  /** 暂无数据兜底高度是否撑满 */
140
141
  noDataFull?: boolean;
141
142
  /** 是否展示暂无数据 */
@@ -148,8 +149,6 @@ export type StkProps = {
148
149
  showOverflow?: boolean;
149
150
  /** 是否增加行hover class */
150
151
  showTrHoverClass?: boolean;
151
- /** 表头是否可拖动 */
152
- headerDrag?: boolean;
153
152
  /** 表头是否可拖动。支持回调函数。 */
154
153
  headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean);
155
154
  /**
@@ -348,6 +347,30 @@ export type StkTableColumn<T extends Record<string, any>> = {
348
347
  ```
349
348
 
350
349
 
350
+ ### StkTableColumn.SortConfig
351
+ ```ts
352
+ /** 排序配置 */
353
+ export type SortConfig<T extends Record<string, any>> = {
354
+ /** 空值始终排在列表末尾 */
355
+ emptyToBottom?: boolean;
356
+ /**
357
+ * 默认排序(1.初始化时触发 2.排序方向为null时触发)
358
+ * 类似onMounted时,调用setSorter点了下表头。
359
+ */
360
+ defaultSort?: {
361
+ dataIndex: keyof T;
362
+ order: Order;
363
+ /** 是否禁止触发sort-change事件。默认false,表示触发事件。 */
364
+ silent?: boolean;
365
+ };
366
+ /**
367
+ * string排序是否使用 String.prototype.localCompare
368
+ * 默认true (&$&应该false)
369
+ */
370
+ stringLocaleCompare?: boolean;
371
+ };
372
+ ```
373
+
351
374
  ### Example
352
375
  ```vue
353
376
  <template>
@@ -420,3 +443,7 @@ export type StkTableColumn<T extends Record<string, any>> = {
420
443
  ### 鼠标悬浮表头时,不展示title
421
444
  * 将 `StkTableColumn` 中的 `title` 字段置为 "" 空字符串。这样th中就没有title了。
422
445
  * 使用 `StkTableColumn` 中的 `customHeaderCell` 属性中,自定义表头渲染。
446
+
447
+
448
+ ## Other
449
+ * `$*$` 兼容注释
@@ -16,9 +16,11 @@ declare function setCurrentRow(rowKey: string, option?: {
16
16
  * @param option.sortOption 指定排序参数。同 StkTableColumn 中排序相关字段。建议从columns中find得到。
17
17
  * @param option.sort 是否触发排序-默认true
18
18
  * @param option.silent 是否禁止触发回调-默认true
19
+ * @param option.force 是否触发排序-默认true
19
20
  */
20
21
  declare function setSorter(dataIndex: string, order: Order, option?: {
21
22
  sortOption?: SortOption<DT>;
23
+ force?: boolean;
22
24
  silent?: boolean;
23
25
  sort?: boolean;
24
26
  }): any[];
@@ -65,7 +67,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
65
67
  /** 列唯一键 */
66
68
  colKey?: UniqKeyProp | undefined;
67
69
  /** 空值展示文字 */
68
- emptyCellText?: string | undefined;
70
+ emptyCellText?: string | ((option: {
71
+ row: any;
72
+ col: StkTableColumn<any>;
73
+ }) => string) | undefined;
69
74
  /** 暂无数据兜底高度是否撑满 */
70
75
  noDataFull?: boolean | undefined;
71
76
  /** 是否展示暂无数据 */
@@ -225,7 +230,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
225
230
  /** 列唯一键 */
226
231
  colKey?: UniqKeyProp | undefined;
227
232
  /** 空值展示文字 */
228
- emptyCellText?: string | undefined;
233
+ emptyCellText?: string | ((option: {
234
+ row: any;
235
+ col: StkTableColumn<any>;
236
+ }) => string) | undefined;
229
237
  /** 暂无数据兜底高度是否撑满 */
230
238
  noDataFull?: boolean | undefined;
231
239
  /** 是否展示暂无数据 */
@@ -345,7 +353,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
345
353
  dataSource: any[];
346
354
  rowKey: UniqKeyProp;
347
355
  colKey: UniqKeyProp;
348
- emptyCellText: string;
356
+ emptyCellText: string | ((option: {
357
+ row: any;
358
+ col: StkTableColumn<any>;
359
+ }) => string);
349
360
  noDataFull: boolean;
350
361
  showNoData: boolean;
351
362
  sortRemote: boolean;
@@ -78,10 +78,15 @@ export type UniqKeyProp = UniqKey | UniqKeyFun;
78
78
  export type SortConfig<T extends Record<string, any>> = {
79
79
  /** 空值始终排在列表末尾 */
80
80
  emptyToBottom?: boolean;
81
- /** 默认排序(1.初始化时触发 2.排序方向为null时触发) */
81
+ /**
82
+ * 默认排序(1.初始化时触发 2.排序方向为null时触发)
83
+ * 类似onMounted时,调用setSorter点了下表头。
84
+ */
82
85
  defaultSort?: {
83
86
  dataIndex: keyof T;
84
87
  order: Order;
88
+ /** 是否禁止触发sort-change事件。默认false,表示触发事件。 */
89
+ silent?: boolean;
85
90
  };
86
91
  /**
87
92
  * string排序是否使用 String.prototype.localCompare
@@ -499,6 +499,7 @@ function useHighlight({ props, tableContainer }) {
499
499
  highlightDimRowKeys.delete(rowKeyValue);
500
500
  }
501
501
  });
502
+ highlightRowStore.value = { ...highlightRowStore.value };
502
503
  if (highlightDimRowKeys.size > 0) {
503
504
  recursion();
504
505
  } else {
@@ -954,7 +955,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
954
955
  dataSource: { default: () => [] },
955
956
  rowKey: { type: [String, Number, Function], default: "" },
956
957
  colKey: { type: [String, Number, Function], default: "dataIndex" },
957
- emptyCellText: { default: "--" },
958
+ emptyCellText: { type: [String, Function], default: "--" },
958
959
  noDataFull: { type: Boolean, default: false },
959
960
  showNoData: { type: Boolean, default: true },
960
961
  sortRemote: { type: Boolean, default: false },
@@ -990,6 +991,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
990
991
  const tableHeaders = ref([]);
991
992
  const tableHeaderLast = ref([]);
992
993
  const dataSourceCopy = shallowRef([...props.dataSource]);
994
+ const getEmptyCellText = computed(() => {
995
+ if (typeof props.emptyCellText === "string") {
996
+ return () => props.emptyCellText;
997
+ } else {
998
+ return (col, row) => props.emptyCellText({ row, col });
999
+ }
1000
+ });
993
1001
  const rowKeyGenStore = /* @__PURE__ */ new WeakMap();
994
1002
  const { isColResizing, onThResizeMouseDown } = useColResize({
995
1003
  props,
@@ -1080,8 +1088,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1080
1088
  function dealDefaultSorter() {
1081
1089
  if (!props.sortConfig.defaultSort)
1082
1090
  return;
1083
- const { dataIndex, order } = props.sortConfig.defaultSort;
1084
- setSorter(dataIndex, order);
1091
+ const { dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
1092
+ setSorter(dataIndex, order, { force: false, silent });
1085
1093
  }
1086
1094
  function dealColumns() {
1087
1095
  tableHeaders.value = [];
@@ -1288,7 +1296,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1288
1296
  if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
1289
1297
  const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
1290
1298
  if (column)
1291
- onColumnSort(column, false, { force: true, emit: !newOption.silent });
1299
+ onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
1292
1300
  else
1293
1301
  console.warn("Can not find column by dataIndex:", sortCol.value);
1294
1302
  }
@@ -1507,7 +1515,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1507
1515
  key: 1,
1508
1516
  class: "table-cell-wrapper",
1509
1517
  title: row[col.dataIndex]
1510
- }, toDisplayString(row[col.dataIndex] ?? _ctx.emptyCellText), 9, _hoisted_14))
1518
+ }, toDisplayString(row[col.dataIndex] ?? getEmptyCellText.value(col, row)), 9, _hoisted_14))
1511
1519
  ], 14, _hoisted_13);
1512
1520
  }), 128))
1513
1521
  ], 46, _hoisted_11);
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "stk-table-vue",
3
- "version": "0.2.5",
4
- "description": "Simple realtime virtual table for vue3&vue2.7",
5
- "main": "./lib/stk-table-vue.js",
6
- "types": "./lib/StkTable/index.d.ts",
7
- "packageManager": "pnpm@8.14.3",
8
- "directories": {
9
- "test": "test"
10
- },
11
- "type": "module",
12
- "scripts": {
13
- "dev": "vite",
14
- "build": "vite build",
15
- "test": "vitest"
16
- },
17
- "keywords": [
18
- "virtual table",
19
- "vue",
20
- "highlight",
21
- "sticky"
22
- ],
23
- "files": [
24
- "lib",
25
- "src"
26
- ],
27
- "author": "japlus",
28
- "repository": {
29
- "type": "git",
30
- "url": "https://gitee.com/japlus/stk-table-vue"
31
- },
32
- "license": "MIT",
33
- "devDependencies": {
34
- "@types/d3-interpolate": "^3.0.4",
35
- "@types/node": "^20.11.14",
36
- "@typescript-eslint/eslint-plugin": "^6.14.0",
37
- "@typescript-eslint/parser": "^6.14.0",
38
- "@vitejs/plugin-vue": "^5.0.3",
39
- "@vitejs/plugin-vue-jsx": "^3.1.0",
40
- "@vue/test-utils": "2.4.4",
41
- "eslint": "^8.55.0",
42
- "eslint-config-prettier": "^9.1.0",
43
- "eslint-plugin-html": "^7.1.0",
44
- "eslint-plugin-prettier": "^5.0.1",
45
- "eslint-plugin-vue": "^9.19.2",
46
- "happy-dom": "^12.10.3",
47
- "less": "^4.2.0",
48
- "postcss-discard-comments": "^6.0.1",
49
- "postcss-preset-env": "^9.3.0",
50
- "prettier": "^3.1.1",
51
- "typescript": "^5.3.3",
52
- "vite": "^5.1.4",
53
- "vite-plugin-dts": "^3.7.3",
54
- "vitest": "^1.1.0",
55
- "vue": "^3.4.19",
56
- "vue-eslint-parser": "^9.3.2"
57
- },
58
- "dependencies": {
59
- "d3-interpolate": "^3.0.1"
60
- }
1
+ {
2
+ "name": "stk-table-vue",
3
+ "version": "0.2.6",
4
+ "description": "Simple realtime virtual table for vue3&vue2.7",
5
+ "main": "./lib/stk-table-vue.js",
6
+ "types": "./lib/src/StkTable/index.d.ts",
7
+ "packageManager": "pnpm@8.14.3",
8
+ "directories": {
9
+ "test": "test"
10
+ },
11
+ "type": "module",
12
+ "scripts": {
13
+ "dev": "vite",
14
+ "build": "vite build",
15
+ "test": "vitest"
16
+ },
17
+ "keywords": [
18
+ "virtual table",
19
+ "vue",
20
+ "highlight",
21
+ "sticky"
22
+ ],
23
+ "files": [
24
+ "lib",
25
+ "src"
26
+ ],
27
+ "author": "japlus",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://gitee.com/japlus/stk-table-vue"
31
+ },
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@types/d3-interpolate": "^3.0.4",
35
+ "@types/node": "^20.11.14",
36
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
37
+ "@typescript-eslint/parser": "^6.14.0",
38
+ "@vitejs/plugin-vue": "^5.0.3",
39
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
40
+ "@vue/test-utils": "2.4.4",
41
+ "eslint": "^8.55.0",
42
+ "eslint-config-prettier": "^9.1.0",
43
+ "eslint-plugin-html": "^7.1.0",
44
+ "eslint-plugin-prettier": "^5.0.1",
45
+ "eslint-plugin-vue": "^9.19.2",
46
+ "happy-dom": "^12.10.3",
47
+ "less": "^4.2.0",
48
+ "postcss-discard-comments": "^6.0.1",
49
+ "postcss-preset-env": "^9.3.0",
50
+ "prettier": "^3.1.1",
51
+ "typescript": "^5.3.3",
52
+ "vite": "^5.1.4",
53
+ "vite-plugin-dts": "^3.7.3",
54
+ "vitest": "^1.1.0",
55
+ "vue": "^3.4.19",
56
+ "vue-eslint-parser": "^9.3.2"
57
+ },
58
+ "dependencies": {
59
+ "d3-interpolate": "^3.0.1"
60
+ }
61
61
  }
@@ -167,7 +167,7 @@
167
167
  >
168
168
  <component :is="col.customCell" v-if="col.customCell" :col="col" :row="row" :cell-value="row[col.dataIndex]" />
169
169
  <div v-else class="table-cell-wrapper" :title="row[col.dataIndex]">
170
- {{ row[col.dataIndex] ?? emptyCellText }}
170
+ {{ row[col.dataIndex] ?? getEmptyCellText(col, row) }}
171
171
  </div>
172
172
  </td>
173
173
  </tr>
@@ -189,7 +189,7 @@
189
189
  * [] 计算的高亮颜色,挂在数据源上对象上,若多个表格使用同一个数据源对象会有问题。需要深拷贝。(解决方案:获取组件uid)
190
190
  * [] highlight-row 颜色不能恢复到active的颜色
191
191
  */
192
- import { CSSProperties, onMounted, ref, shallowRef, toRaw, watch } from 'vue';
192
+ import { CSSProperties, computed, onMounted, ref, shallowRef, toRaw, watch } from 'vue';
193
193
  import { Default_Row_Height } from './const';
194
194
  import { Order, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
195
195
  import { useAutoResize } from './useAutoResize';
@@ -239,7 +239,7 @@ const props = withDefaults(
239
239
  /** 列唯一键 */
240
240
  colKey?: UniqKeyProp;
241
241
  /** 空值展示文字 */
242
- emptyCellText?: string; //TODO: 支持传入方法
242
+ emptyCellText?: string | ((option: { row: DT; col: StkTableColumn<DT> }) => string);
243
243
  /** 暂无数据兜底高度是否撑满 */
244
244
  noDataFull?: boolean;
245
245
  /** 是否展示暂无数据 */
@@ -258,7 +258,7 @@ const props = withDefaults(
258
258
  * 给行附加className<br>
259
259
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
260
260
  */
261
- rowClassName?: (row: any, i: number) => string;
261
+ rowClassName?: (row: DT, i: number) => string;
262
262
  /**
263
263
  * 列宽是否可拖动<br>
264
264
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -446,6 +446,15 @@ const dataSourceCopy = shallowRef<DT[]>([...props.dataSource]);
446
446
  /**高亮帧间隔
447
447
  const highlightStepDuration = Highlight_Color_Change_Freq / 1000 + 's';*/
448
448
 
449
+ /** 空单元格占位字符 */
450
+ const getEmptyCellText = computed(() => {
451
+ if (typeof props.emptyCellText === 'string') {
452
+ return () => props.emptyCellText;
453
+ } else {
454
+ return (col: StkTableColumn<DT>, row: DT) => (props.emptyCellText as any)({ row, col });
455
+ }
456
+ });
457
+
449
458
  /** rowKey缓存 */
450
459
  const rowKeyGenStore = new WeakMap();
451
460
 
@@ -558,8 +567,8 @@ onMounted(() => {
558
567
  /** 处理默认排序 */
559
568
  function dealDefaultSorter() {
560
569
  if (!props.sortConfig.defaultSort) return;
561
- const { dataIndex, order } = props.sortConfig.defaultSort;
562
- setSorter(dataIndex as string, order);
570
+ const { dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
571
+ setSorter(dataIndex as string, order, { force: false, silent });
563
572
  }
564
573
 
565
574
  /**
@@ -859,8 +868,9 @@ function setCurrentRow(rowKey: string, option = { silent: false }) {
859
868
  * @param option.sortOption 指定排序参数。同 StkTableColumn 中排序相关字段。建议从columns中find得到。
860
869
  * @param option.sort 是否触发排序-默认true
861
870
  * @param option.silent 是否禁止触发回调-默认true
871
+ * @param option.force 是否触发排序-默认true
862
872
  */
863
- function setSorter(dataIndex: string, order: Order, option: { sortOption?: SortOption<DT>; silent?: boolean; sort?: boolean } = {}) {
873
+ function setSorter(dataIndex: string, order: Order, option: { sortOption?: SortOption<DT>; force?: boolean; silent?: boolean; sort?: boolean } = {}) {
864
874
  const newOption = { silent: true, sortOption: null, sort: true, ...option };
865
875
  sortCol.value = dataIndex;
866
876
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
@@ -868,7 +878,7 @@ function setSorter(dataIndex: string, order: Order, option: { sortOption?: SortO
868
878
  if (newOption.sort && dataSourceCopy.value?.length) {
869
879
  // 如果表格有数据,则进行排序
870
880
  const column = newOption.sortOption || tableHeaderLast.value.find(it => it.dataIndex === sortCol.value);
871
- if (column) onColumnSort(column, false, { force: true, emit: !newOption.silent });
881
+ if (column) onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
872
882
  else console.warn('Can not find column by dataIndex:', sortCol.value);
873
883
  }
874
884
  return dataSourceCopy.value;
@@ -77,10 +77,15 @@ export type UniqKeyProp = UniqKey | UniqKeyFun;
77
77
  export type SortConfig<T extends Record<string, any>> = {
78
78
  /** 空值始终排在列表末尾 */
79
79
  emptyToBottom?: boolean;
80
- /** 默认排序(1.初始化时触发 2.排序方向为null时触发) */
80
+ /**
81
+ * 默认排序(1.初始化时触发 2.排序方向为null时触发)
82
+ * 类似onMounted时,调用setSorter点了下表头。
83
+ */
81
84
  defaultSort?: {
82
85
  dataIndex: keyof T;
83
86
  order: Order;
87
+ /** 是否禁止触发sort-change事件。默认false,表示触发事件。 */
88
+ silent?: boolean;
84
89
  };
85
90
  /**
86
91
  * string排序是否使用 String.prototype.localCompare
@@ -76,6 +76,9 @@ export function useHighlight({ props, tableContainer }: Params) {
76
76
  }
77
77
  });
78
78
 
79
+ // $*$ 兼容vue2响应
80
+ highlightRowStore.value = { ...highlightRowStore.value };
81
+
79
82
  if (highlightDimRowKeys.size > 0) {
80
83
  // 还有高亮的行,则下一次循环
81
84
  recursion();