stk-table-vue 0.11.13 → 0.11.14

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: stk-table-vue
3
- * version: v0.11.12
3
+ * version: v0.11.14
4
4
  * description: High performance realtime virtual table for vue3 and vue2.7
5
5
  * author: japlus
6
6
  * homepage: https://ja-plus.github.io/stk-table-vue/
@@ -0,0 +1,4 @@
1
+ import { Ref } from 'vue';
2
+ import { StkTableColumn, UniqKey } from './types';
3
+
4
+ export declare function useIndexResolver<DT extends Record<string, any>>(dataSourceRef: Ref<DT[]>, columnsRef: Ref<StkTableColumn<DT>[]>, rowKeyGen: (row: DT | null | undefined) => UniqKey): readonly [(row: DT) => number, (column: StkTableColumn<DT>) => number];
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: stk-table-vue
3
- * version: v0.11.12
3
+ * version: v0.11.14
4
4
  * description: High performance realtime virtual table for vue3 and vue2.7
5
5
  * author: japlus
6
6
  * homepage: https://ja-plus.github.io/stk-table-vue/
@@ -54,7 +54,7 @@ function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {})
54
54
  }
55
55
  const { emptyToBottom, customCompare, stringLocaleCompare } = { emptyToBottom: false, ...sortConfig };
56
56
  const targetVal = newItem[field];
57
- if (emptyToBottom && isEmptyValue(targetVal)) {
57
+ if (emptyToBottom && isEmptyValue(targetVal, sortType === "number")) {
58
58
  data.push(newItem);
59
59
  } else {
60
60
  const customCompareFn = customCompare || ((a, b) => {
package/lib/style.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: stk-table-vue
3
- * version: v0.11.12
3
+ * version: v0.11.14
4
4
  * description: High performance realtime virtual table for vue3 and vue2.7
5
5
  * author: japlus
6
6
  * homepage: https://ja-plus.github.io/stk-table-vue/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.11.13",
3
+ "version": "0.11.14",
4
4
  "description": "High performance realtime virtual table for vue3 and vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -296,6 +296,7 @@ import { useTableColumns } from './useTableColumns';
296
296
  import { useThDrag } from './useThDrag';
297
297
  import { useTrDrag } from './useTrDrag';
298
298
  import { useTree } from './useTree';
299
+ import { useIndexResolver } from './useIndexResolver';
299
300
  import { useVirtualScroll } from './useVirtualScroll';
300
301
  import { useWheeling } from './useWheeling';
301
302
  import { createStkTableId, getCalculatedColWidth } from './utils/constRefUtils';
@@ -0,0 +1,29 @@
1
+ import type { Ref } from 'vue';
2
+ import type { StkTableColumn, UniqKey } from './types';
3
+
4
+ export function useIndexResolver<DT extends Record<string, any>>(
5
+ dataSourceRef: Ref<DT[]>,
6
+ columnsRef: Ref<StkTableColumn<DT>[]>,
7
+ rowKeyGen: (row: DT | null | undefined) => UniqKey,
8
+ ) {
9
+ function getRowIndex(row: DT): number {
10
+ const targetKey = rowKeyGen(row);
11
+ const data = dataSourceRef.value;
12
+ for (let i = 0; i < data.length; i++) {
13
+ if (rowKeyGen(data[i]) === targetKey) return i;
14
+ }
15
+ return -1;
16
+ }
17
+
18
+ function getColumnIndex(column: StkTableColumn<DT>): number {
19
+ const targetDataIndex = column?.dataIndex;
20
+ if (targetDataIndex === void 0 || targetDataIndex === null) return -1;
21
+ const columns = columnsRef.value;
22
+ for (let i = 0; i < columns.length; i++) {
23
+ if (columns[i]?.dataIndex === targetDataIndex) return i;
24
+ }
25
+ return -1;
26
+ }
27
+
28
+ return [getRowIndex, getColumnIndex] as const;
29
+ }
@@ -43,7 +43,7 @@ export function insertToOrderedArray<T extends object>(
43
43
  const { emptyToBottom, customCompare, stringLocaleCompare } = { emptyToBottom: false, ...sortConfig };
44
44
 
45
45
  const targetVal: any = newItem[field];
46
- if (emptyToBottom && isEmptyValue(targetVal)) {
46
+ if (emptyToBottom && isEmptyValue(targetVal, sortType === 'number')) {
47
47
  // 空值排在最下方
48
48
  data.push(newItem);
49
49
  } else {