stk-table-vue 0.6.2 → 0.6.3
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 +1 -1
- package/lib/src/StkTable/StkTable.vue.d.ts +13 -10
- package/lib/src/StkTable/types/index.d.ts +6 -1
- package/lib/src/StkTable/useGetFixedColPosition.d.ts +2 -2
- package/lib/src/StkTable/useHighlight.d.ts +1 -1
- package/lib/src/StkTable/useThDrag.d.ts +1 -1
- package/lib/src/StkTable/utils/index.d.ts +2 -2
- package/lib/stk-table-vue.js +76 -54
- package/lib/style.css +11 -8
- package/package.json +69 -63
- package/src/StkTable/StkTable.vue +87 -50
- package/src/StkTable/style.less +23 -18
- package/src/StkTable/types/index.ts +6 -1
- package/src/StkTable/useFixedCol.ts +1 -0
- package/src/StkTable/useFixedStyle.ts +2 -1
- package/src/StkTable/useGetFixedColPosition.ts +8 -8
- package/src/StkTable/useHighlight.ts +3 -3
- package/src/StkTable/useThDrag.ts +2 -2
- package/src/StkTable/utils/index.ts +3 -3
- package/src/VirtualTreeSelect.vue +67 -33
package/README.md
CHANGED
|
@@ -180,7 +180,7 @@ export type StkProps = {
|
|
|
180
180
|
dataSource?: any[];
|
|
181
181
|
/** 行唯一键 (行唯一值不能为undefined)*/
|
|
182
182
|
rowKey?: UniqKeyProp;
|
|
183
|
-
/**
|
|
183
|
+
/** 列唯一键。默认`dataIndex`*/
|
|
184
184
|
colKey?: UniqKeyProp;
|
|
185
185
|
/** 空值展示文字 */
|
|
186
186
|
emptyCellText?: string | ((option: { row: DT; col: StkTableColumn<DT> }) => string);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AutoRowHeightConfig, DragRowConfig, ExpandConfig, HeaderDragConfig, HighlightConfig, Order, PrivateRowDT, SeqConfig, SortConfig, SortOption,
|
|
1
|
+
import { AutoRowHeightConfig, DragRowConfig, ExpandConfig, HeaderDragConfig, HighlightConfig, Order, PrivateRowDT, SeqConfig, SortConfig, SortOption, StkTableColumn, UniqKeyProp } from './types/index';
|
|
2
2
|
/** Generic stands for DataType */
|
|
3
3
|
type DT = any & PrivateRowDT;
|
|
4
4
|
/**
|
|
@@ -19,15 +19,15 @@ declare function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option?: {
|
|
|
19
19
|
silent: boolean;
|
|
20
20
|
}): void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param
|
|
22
|
+
* 设置表头排序状态。
|
|
23
|
+
* @param colKey 列唯一键字段。如果你想要取消排序状态,请使用`resetSorter`
|
|
24
24
|
* @param order 正序倒序
|
|
25
25
|
* @param option.sortOption 指定排序参数。同 StkTableColumn 中排序相关字段。建议从columns中find得到。
|
|
26
26
|
* @param option.sort 是否触发排序-默认true
|
|
27
27
|
* @param option.silent 是否禁止触发回调-默认true
|
|
28
28
|
* @param option.force 是否触发排序-默认true
|
|
29
29
|
*/
|
|
30
|
-
declare function setSorter(
|
|
30
|
+
declare function setSorter(colKey: string, order: Order, option?: {
|
|
31
31
|
sortOption?: SortOption<DT>;
|
|
32
32
|
force?: boolean;
|
|
33
33
|
silent?: boolean;
|
|
@@ -43,7 +43,10 @@ declare function scrollTo(top?: number | null, left?: number | null): void;
|
|
|
43
43
|
/** get current table data */
|
|
44
44
|
declare function getTableData(): any[];
|
|
45
45
|
/** get current sort info */
|
|
46
|
-
declare function getSortColumns():
|
|
46
|
+
declare function getSortColumns(): {
|
|
47
|
+
key: string | number | symbol | undefined;
|
|
48
|
+
order: "desc" | "asc";
|
|
49
|
+
}[];
|
|
47
50
|
/**
|
|
48
51
|
*
|
|
49
52
|
* @param rowKeyOrRow rowKey or row
|
|
@@ -158,7 +161,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
|
|
|
158
161
|
optimizeVue2Scroll?: boolean | undefined;
|
|
159
162
|
/** 排序配置 */
|
|
160
163
|
sortConfig?: SortConfig<any> | undefined;
|
|
161
|
-
/** 隐藏头部title。可传入
|
|
164
|
+
/** 隐藏头部title。可传入colKey数组 */
|
|
162
165
|
hideHeaderTitle?: boolean | string[] | undefined;
|
|
163
166
|
/** 高亮配置 */
|
|
164
167
|
highlightConfig?: HighlightConfig | undefined;
|
|
@@ -226,7 +229,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
|
|
|
226
229
|
* en: Set highlight cell
|
|
227
230
|
* @see {@link setHighlightDimCell}
|
|
228
231
|
*/
|
|
229
|
-
setHighlightDimCell: (rowKeyValue: import('./types/index').UniqKey,
|
|
232
|
+
setHighlightDimCell: (rowKeyValue: import('./types/index').UniqKey, colKeyValue: string, option?: import('./types/highlightDimOptions').HighlightDimCellOption) => void;
|
|
230
233
|
/**
|
|
231
234
|
* 设置高亮行
|
|
232
235
|
*
|
|
@@ -235,9 +238,9 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
|
|
|
235
238
|
*/
|
|
236
239
|
setHighlightDimRow: (rowKeyValues: import('./types/index').UniqKey[], option?: import('./types/highlightDimOptions').HighlightDimRowOption) => void;
|
|
237
240
|
/**
|
|
238
|
-
* 表格排序列
|
|
241
|
+
* 表格排序列colKey
|
|
239
242
|
*
|
|
240
|
-
* en: Table sort column
|
|
243
|
+
* en: Table sort column colKey
|
|
241
244
|
*/
|
|
242
245
|
sortCol: import('vue').Ref<string | number | symbol | undefined, string | number | symbol | undefined>;
|
|
243
246
|
/**
|
|
@@ -403,7 +406,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
|
|
|
403
406
|
optimizeVue2Scroll?: boolean | undefined;
|
|
404
407
|
/** 排序配置 */
|
|
405
408
|
sortConfig?: SortConfig<any> | undefined;
|
|
406
|
-
/** 隐藏头部title。可传入
|
|
409
|
+
/** 隐藏头部title。可传入colKey数组 */
|
|
407
410
|
hideHeaderTitle?: boolean | string[] | undefined;
|
|
408
411
|
/** 高亮配置 */
|
|
409
412
|
highlightConfig?: HighlightConfig | undefined;
|
|
@@ -38,7 +38,6 @@ export type CustomCell<T extends CustomCellProps<U> | CustomHeaderCellProps<U>,
|
|
|
38
38
|
export type StkTableColumn<T extends Record<string, any>> = {
|
|
39
39
|
/**
|
|
40
40
|
* 用于区分相同dataIndex 的列。
|
|
41
|
-
* 需要自行配置colKey="(col: StkTableColumn<any>) => col.key ?? col.dataIndex"
|
|
42
41
|
*/
|
|
43
42
|
key?: any;
|
|
44
43
|
/**
|
|
@@ -144,6 +143,12 @@ export type SortConfig<T extends Record<string, any>> = {
|
|
|
144
143
|
* 类似onMounted时,调用setSorter点了下表头。
|
|
145
144
|
*/
|
|
146
145
|
defaultSort?: {
|
|
146
|
+
/**
|
|
147
|
+
* 列唯一键,
|
|
148
|
+
*
|
|
149
|
+
* 如果您配了 `props.colKey` 则这里表示的列唯一键的值
|
|
150
|
+
*/
|
|
151
|
+
key?: StkTableColumn<T>['key'];
|
|
147
152
|
dataIndex: StkTableColumn<T>['dataIndex'];
|
|
148
153
|
order: Order;
|
|
149
154
|
sortField?: StkTableColumn<T>['sortField'];
|
|
@@ -2,12 +2,12 @@ import { ComputedRef, ShallowRef } from 'vue';
|
|
|
2
2
|
import { StkTableColumn, UniqKey } from './types';
|
|
3
3
|
type Params<T extends Record<string, any>> = {
|
|
4
4
|
colKeyGen: ComputedRef<(col: StkTableColumn<T>) => UniqKey>;
|
|
5
|
-
|
|
5
|
+
tableHeadersForCalc: ShallowRef<StkTableColumn<T>[][]>;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* 固定列fixed左侧或者右侧的距离
|
|
9
9
|
* - col.fixed = left 则得到距离左侧的距离
|
|
10
10
|
* - col.fixed = right 则得到距离右侧的距离
|
|
11
11
|
*/
|
|
12
|
-
export declare function useGetFixedColPosition<DT extends Record<string, any>>({
|
|
12
|
+
export declare function useGetFixedColPosition<DT extends Record<string, any>>({ tableHeadersForCalc, colKeyGen }: Params<DT>): ComputedRef<(col: StkTableColumn<any>) => number>;
|
|
13
13
|
export {};
|
|
@@ -12,6 +12,6 @@ type Params = {
|
|
|
12
12
|
export declare function useHighlight({ props, stkTableId, tableContainerRef }: Params): {
|
|
13
13
|
highlightSteps: number | null;
|
|
14
14
|
setHighlightDimRow: (rowKeyValues: UniqKey[], option?: HighlightDimRowOption) => void;
|
|
15
|
-
setHighlightDimCell: (rowKeyValue: UniqKey,
|
|
15
|
+
setHighlightDimCell: (rowKeyValue: UniqKey, colKeyValue: string, option?: HighlightDimCellOption) => void;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
@@ -14,6 +14,6 @@ export declare function useThDrag<DT extends Record<string, any>>({ props, emits
|
|
|
14
14
|
onThDragOver: (e: DragEvent) => void;
|
|
15
15
|
onThDrop: (e: DragEvent) => void;
|
|
16
16
|
/** 是否可拖拽 */
|
|
17
|
-
isHeaderDraggable: (col: StkTableColumn<DT>) =>
|
|
17
|
+
isHeaderDraggable: (col: StkTableColumn<DT>) => any;
|
|
18
18
|
};
|
|
19
19
|
export {};
|
|
@@ -4,7 +4,7 @@ import { Order, SortConfig, SortOption, SortState, StkTableColumn } from '../typ
|
|
|
4
4
|
*
|
|
5
5
|
* 注意:不会改变原数组,返回新数组
|
|
6
6
|
* @param sortState
|
|
7
|
-
* @param sortState.dataIndex
|
|
7
|
+
* @param sortState.dataIndex 排序的字段
|
|
8
8
|
* @param sortState.order 排序顺序
|
|
9
9
|
* @param sortState.sortType 排序方式
|
|
10
10
|
* @param newItem 要插入的数据
|
|
@@ -34,7 +34,7 @@ export declare function strCompare(a: string, b: string, isNumber: boolean, loca
|
|
|
34
34
|
* @param dataSource 排序的数组
|
|
35
35
|
*/
|
|
36
36
|
export declare function tableSort<T extends Record<string, any>>(sortOption: SortOption<T>, order: Order, dataSource: T[], sortConfig?: SortConfig<T>): T[];
|
|
37
|
-
/**
|
|
37
|
+
/** 多级表头深度 从0开始为一级*/
|
|
38
38
|
export declare function howDeepTheHeader(arr: StkTableColumn<any>[], level?: number): number;
|
|
39
39
|
/** number列宽+px */
|
|
40
40
|
export declare function transformWidthToStr(width?: string | number): string | undefined;
|
package/lib/stk-table-vue.js
CHANGED
|
@@ -147,7 +147,7 @@ function tableSort(sortOption, order, dataSource, sortConfig = {}) {
|
|
|
147
147
|
}
|
|
148
148
|
return targetDataSource;
|
|
149
149
|
}
|
|
150
|
-
function howDeepTheHeader(arr, level =
|
|
150
|
+
function howDeepTheHeader(arr, level = 0) {
|
|
151
151
|
const levels = [level];
|
|
152
152
|
arr.forEach((item) => {
|
|
153
153
|
var _a;
|
|
@@ -529,7 +529,8 @@ function useFixedStyle({
|
|
|
529
529
|
if (isRelativeMode.value) {
|
|
530
530
|
style.top = virtualScroll.value.scrollTop + "px";
|
|
531
531
|
} else {
|
|
532
|
-
|
|
532
|
+
const rowHeight = props.headerRowHeight ?? props.rowHeight;
|
|
533
|
+
style.top = depth * rowHeight + "px";
|
|
533
534
|
}
|
|
534
535
|
}
|
|
535
536
|
const { scrollLeft, scrollWidth, offsetLeft, containerWidth } = virtualScrollX.value;
|
|
@@ -554,17 +555,17 @@ function useFixedStyle({
|
|
|
554
555
|
}
|
|
555
556
|
return getFixedStyle;
|
|
556
557
|
}
|
|
557
|
-
function useGetFixedColPosition({
|
|
558
|
+
function useGetFixedColPosition({ tableHeadersForCalc, colKeyGen }) {
|
|
558
559
|
const getFixedColPosition = computed(() => {
|
|
559
560
|
const colKeyStore = {};
|
|
560
561
|
const refStore = /* @__PURE__ */ new WeakMap();
|
|
561
|
-
|
|
562
|
+
tableHeadersForCalc.value.forEach((cols) => {
|
|
562
563
|
let left = 0;
|
|
563
564
|
let rightStartIndex = 0;
|
|
564
565
|
for (let i = 0; i < cols.length; i++) {
|
|
565
566
|
const item = cols[i];
|
|
566
567
|
if (item.fixed === "left") {
|
|
567
|
-
const colKey = colKeyGen.value(item)
|
|
568
|
+
const colKey = colKeyGen.value(item);
|
|
568
569
|
if (colKey) {
|
|
569
570
|
colKeyStore[colKey] = left;
|
|
570
571
|
} else {
|
|
@@ -579,7 +580,7 @@ function useGetFixedColPosition({ tableHeaders, colKeyGen }) {
|
|
|
579
580
|
let right = 0;
|
|
580
581
|
for (let i = cols.length - 1; i >= rightStartIndex; i--) {
|
|
581
582
|
const item = cols[i];
|
|
582
|
-
const colKey = colKeyGen.value(item)
|
|
583
|
+
const colKey = colKeyGen.value(item);
|
|
583
584
|
if (item.fixed === "right") {
|
|
584
585
|
if (colKey) {
|
|
585
586
|
colKeyStore[colKey] = right;
|
|
@@ -591,7 +592,7 @@ function useGetFixedColPosition({ tableHeaders, colKeyGen }) {
|
|
|
591
592
|
}
|
|
592
593
|
});
|
|
593
594
|
return (col) => {
|
|
594
|
-
const colKey = colKeyGen.value(col)
|
|
595
|
+
const colKey = colKeyGen.value(col);
|
|
595
596
|
return colKey ? colKeyStore[colKey] : refStore.get(col) || 0;
|
|
596
597
|
};
|
|
597
598
|
});
|
|
@@ -675,9 +676,9 @@ function useHighlight({ props, stkTableId, tableContainerRef }) {
|
|
|
675
676
|
};
|
|
676
677
|
recursion();
|
|
677
678
|
}
|
|
678
|
-
function setHighlightDimCell(rowKeyValue,
|
|
679
|
+
function setHighlightDimCell(rowKeyValue, colKeyValue, option = {}) {
|
|
679
680
|
var _a;
|
|
680
|
-
const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-
|
|
681
|
+
const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-cell-key="${rowKeyValue}--${colKeyValue}"]`);
|
|
681
682
|
const { className, method, duration, keyframe } = {
|
|
682
683
|
className: HIGHLIGHT_CELL_CLASS,
|
|
683
684
|
method: "animation",
|
|
@@ -939,7 +940,7 @@ function useThDrag({ props, emits, colKeyGen }) {
|
|
|
939
940
|
onThDragOver,
|
|
940
941
|
onThDrop,
|
|
941
942
|
/** 是否可拖拽 */
|
|
942
|
-
isHeaderDraggable: (col) => !dragConfig.value.disabled(col)
|
|
943
|
+
isHeaderDraggable: (col) => dragConfig.value.draggable && !dragConfig.value.disabled(col)
|
|
943
944
|
};
|
|
944
945
|
}
|
|
945
946
|
const TR_DRAGGING_CLASS = "tr-dragging";
|
|
@@ -1334,7 +1335,7 @@ const _hoisted_9 = {
|
|
|
1334
1335
|
};
|
|
1335
1336
|
const _hoisted_10 = ["colspan"];
|
|
1336
1337
|
const _hoisted_11 = { class: "table-cell-wrapper" };
|
|
1337
|
-
const _hoisted_12 = ["data-
|
|
1338
|
+
const _hoisted_12 = ["data-cell-key", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
|
|
1338
1339
|
const _hoisted_13 = ["title"];
|
|
1339
1340
|
const _hoisted_14 = { key: 1 };
|
|
1340
1341
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -1409,6 +1410,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1409
1410
|
const sortSwitchOrder = [null, "desc", "asc"];
|
|
1410
1411
|
const tableHeaders = shallowRef([]);
|
|
1411
1412
|
const tableHeaderLast = shallowRef([]);
|
|
1413
|
+
const tableHeadersForCalc = shallowRef([]);
|
|
1412
1414
|
const dataSourceCopy = shallowRef([...props.dataSource]);
|
|
1413
1415
|
const colKeyGen = computed(() => {
|
|
1414
1416
|
if (typeof props.colKey === "function") {
|
|
@@ -1444,7 +1446,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1444
1446
|
setAutoHeight,
|
|
1445
1447
|
clearAllAutoHeight
|
|
1446
1448
|
} = useVirtualScroll({ tableContainerRef, trRef, props, dataSourceCopy, tableHeaderLast, tableHeaders, rowKeyGen });
|
|
1447
|
-
const getFixedColPosition = useGetFixedColPosition({ colKeyGen,
|
|
1449
|
+
const getFixedColPosition = useGetFixedColPosition({ colKeyGen, tableHeadersForCalc });
|
|
1448
1450
|
const getFixedStyle = useFixedStyle({
|
|
1449
1451
|
props,
|
|
1450
1452
|
isRelativeMode,
|
|
@@ -1527,7 +1529,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1527
1529
|
nextTick(() => initVirtualScrollY());
|
|
1528
1530
|
}
|
|
1529
1531
|
if (sortCol.value) {
|
|
1530
|
-
const column = tableHeaderLast.value.find((it) => it
|
|
1532
|
+
const column = tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
|
|
1531
1533
|
onColumnSort(column, false);
|
|
1532
1534
|
}
|
|
1533
1535
|
},
|
|
@@ -1547,11 +1549,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1547
1549
|
});
|
|
1548
1550
|
function dealDefaultSorter() {
|
|
1549
1551
|
if (!props.sortConfig.defaultSort) return;
|
|
1550
|
-
const { dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
|
|
1551
|
-
setSorter(dataIndex, order, { force: false, silent });
|
|
1552
|
+
const { key, dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
|
|
1553
|
+
setSorter(key || dataIndex, order, { force: false, silent });
|
|
1552
1554
|
}
|
|
1553
1555
|
function dealColumns() {
|
|
1554
|
-
|
|
1556
|
+
const tableHeadersTemp = [];
|
|
1557
|
+
const tableHeadersForCalcTemp = [];
|
|
1555
1558
|
let copyColumn = props.columns;
|
|
1556
1559
|
if (isRelativeMode.value) {
|
|
1557
1560
|
let leftCol = [];
|
|
@@ -1568,15 +1571,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1568
1571
|
});
|
|
1569
1572
|
copyColumn = [...leftCol, ...centerCol, ...rightCol];
|
|
1570
1573
|
}
|
|
1571
|
-
const
|
|
1574
|
+
const maxDeep = howDeepTheHeader(copyColumn);
|
|
1572
1575
|
const tempHeaderLast = [];
|
|
1573
|
-
if (
|
|
1576
|
+
if (maxDeep > 0 && props.virtualX) {
|
|
1574
1577
|
console.error("多级表头不支持横向虚拟滚动");
|
|
1575
1578
|
}
|
|
1579
|
+
for (let i = 0; i <= maxDeep; i++) {
|
|
1580
|
+
tableHeadersTemp[i] = [];
|
|
1581
|
+
tableHeadersForCalcTemp[i] = [];
|
|
1582
|
+
}
|
|
1576
1583
|
function flat(arr, parent, depth = 0) {
|
|
1577
|
-
if (!tableHeadersTemp[depth]) {
|
|
1578
|
-
tableHeadersTemp[depth] = [];
|
|
1579
|
-
}
|
|
1580
1584
|
let allChildrenLen = 0;
|
|
1581
1585
|
let allChildrenWidthSum = 0;
|
|
1582
1586
|
arr.forEach((col) => {
|
|
@@ -1592,20 +1596,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1592
1596
|
);
|
|
1593
1597
|
colChildrenLen = len;
|
|
1594
1598
|
colWidth = widthSum;
|
|
1599
|
+
tableHeadersForCalcTemp[depth].push(col);
|
|
1595
1600
|
} else {
|
|
1596
1601
|
colWidth = getColWidth(col);
|
|
1597
1602
|
tempHeaderLast.push(col);
|
|
1603
|
+
for (let i = depth; i <= maxDeep; i++) {
|
|
1604
|
+
tableHeadersForCalcTemp[i].push(col);
|
|
1605
|
+
}
|
|
1598
1606
|
}
|
|
1607
|
+
col.__WIDTH__ = colWidth;
|
|
1599
1608
|
tableHeadersTemp[depth].push(col);
|
|
1600
|
-
const rowSpan = col.children ? 1 :
|
|
1609
|
+
const rowSpan = col.children ? 1 : maxDeep - depth + 1;
|
|
1601
1610
|
const colSpan = colChildrenLen;
|
|
1602
|
-
if (rowSpan
|
|
1611
|
+
if (rowSpan > 1) {
|
|
1603
1612
|
col.rowSpan = rowSpan;
|
|
1604
1613
|
}
|
|
1605
|
-
if (colSpan
|
|
1614
|
+
if (colSpan > 1) {
|
|
1606
1615
|
col.colSpan = colSpan;
|
|
1607
1616
|
}
|
|
1608
|
-
col.__WIDTH__ = colWidth;
|
|
1609
1617
|
allChildrenLen += colChildrenLen;
|
|
1610
1618
|
allChildrenWidthSum += colWidth;
|
|
1611
1619
|
});
|
|
@@ -1614,6 +1622,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1614
1622
|
flat(copyColumn, null);
|
|
1615
1623
|
tableHeaders.value = tableHeadersTemp;
|
|
1616
1624
|
tableHeaderLast.value = tempHeaderLast;
|
|
1625
|
+
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
1617
1626
|
}
|
|
1618
1627
|
function rowKeyGen(row) {
|
|
1619
1628
|
if (!row) return row;
|
|
@@ -1669,18 +1678,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1669
1678
|
};
|
|
1670
1679
|
});
|
|
1671
1680
|
function getHeaderTitle(col) {
|
|
1672
|
-
|
|
1681
|
+
const colKey = colKeyGen.value(col);
|
|
1682
|
+
if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(colKey)) {
|
|
1673
1683
|
return "";
|
|
1674
1684
|
}
|
|
1675
1685
|
return col.title || "";
|
|
1676
1686
|
}
|
|
1677
1687
|
function onColumnSort(col, click = true, options = {}) {
|
|
1678
|
-
if (!
|
|
1688
|
+
if (!col) {
|
|
1689
|
+
console.warn("onColumnSort: col is not found");
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
if (!col.sorter && click) {
|
|
1679
1693
|
return;
|
|
1680
1694
|
}
|
|
1681
1695
|
options = { force: false, emit: false, ...options };
|
|
1682
|
-
|
|
1683
|
-
|
|
1696
|
+
const colKey = colKeyGen.value(col);
|
|
1697
|
+
if (sortCol.value !== colKey) {
|
|
1698
|
+
sortCol.value = colKey;
|
|
1684
1699
|
sortOrderIndex.value = 0;
|
|
1685
1700
|
}
|
|
1686
1701
|
if (click) sortOrderIndex.value++;
|
|
@@ -1689,14 +1704,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1689
1704
|
const sortConfig = props.sortConfig;
|
|
1690
1705
|
const defaultSort = sortConfig.defaultSort;
|
|
1691
1706
|
if (!order && defaultSort) {
|
|
1692
|
-
|
|
1693
|
-
|
|
1707
|
+
const colKey2 = defaultSort.key || defaultSort.dataIndex;
|
|
1708
|
+
if (!colKey2) {
|
|
1709
|
+
console.error("sortConfig.defaultSort key or dataIndex is required");
|
|
1694
1710
|
return;
|
|
1695
1711
|
}
|
|
1696
1712
|
order = defaultSort.order || "desc";
|
|
1697
1713
|
sortOrderIndex.value = sortSwitchOrder.indexOf(order);
|
|
1698
|
-
sortCol.value =
|
|
1699
|
-
col =
|
|
1714
|
+
sortCol.value = colKey2;
|
|
1715
|
+
col = null;
|
|
1716
|
+
for (const row of tableHeaders.value) {
|
|
1717
|
+
const c = row.find((item) => colKeyGen.value(item) === colKey2);
|
|
1718
|
+
if (c) {
|
|
1719
|
+
col = c;
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1700
1723
|
}
|
|
1701
1724
|
if (!props.sortRemote || options.force) {
|
|
1702
1725
|
const sortOption = col || defaultSort;
|
|
@@ -1859,15 +1882,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1859
1882
|
);
|
|
1860
1883
|
}
|
|
1861
1884
|
}
|
|
1862
|
-
function setSorter(
|
|
1885
|
+
function setSorter(colKey, order, option = {}) {
|
|
1863
1886
|
var _a;
|
|
1864
1887
|
const newOption = { silent: true, sortOption: null, sort: true, ...option };
|
|
1865
|
-
sortCol.value =
|
|
1888
|
+
sortCol.value = colKey;
|
|
1866
1889
|
sortOrderIndex.value = sortSwitchOrder.indexOf(order);
|
|
1867
1890
|
if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
|
|
1868
|
-
const column = newOption.sortOption || tableHeaderLast.value.find((it) => it
|
|
1891
|
+
const column = newOption.sortOption || tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
|
|
1869
1892
|
if (column) onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
|
|
1870
|
-
else console.warn("Can not find column by
|
|
1893
|
+
else console.warn("Can not find column by key:", sortCol.value);
|
|
1871
1894
|
}
|
|
1872
1895
|
return dataSourceCopy.value;
|
|
1873
1896
|
}
|
|
@@ -1887,7 +1910,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1887
1910
|
function getSortColumns() {
|
|
1888
1911
|
const sortOrder = sortSwitchOrder[sortOrderIndex.value];
|
|
1889
1912
|
if (!sortOrder) return [];
|
|
1890
|
-
return [{
|
|
1913
|
+
return [{ key: sortCol.value, order: sortOrder }];
|
|
1891
1914
|
}
|
|
1892
1915
|
function toggleExpandRow(row, col) {
|
|
1893
1916
|
const isExpand = (row == null ? void 0 : row.__EXPANDED__) === col ? !(row == null ? void 0 : row.__EXPANDED__) : true;
|
|
@@ -1985,9 +2008,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1985
2008
|
*/
|
|
1986
2009
|
setHighlightDimRow,
|
|
1987
2010
|
/**
|
|
1988
|
-
* 表格排序列
|
|
2011
|
+
* 表格排序列colKey
|
|
1989
2012
|
*
|
|
1990
|
-
* en: Table sort column
|
|
2013
|
+
* en: Table sort column colKey
|
|
1991
2014
|
*/
|
|
1992
2015
|
sortCol,
|
|
1993
2016
|
/**
|
|
@@ -2111,7 +2134,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2111
2134
|
}, null, 4)) : createCommentVNode("", true),
|
|
2112
2135
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
|
|
2113
2136
|
return openBlock(), createElementBlock("th", {
|
|
2114
|
-
key: col
|
|
2137
|
+
key: colKeyGen.value(col),
|
|
2115
2138
|
"data-col-key": colKeyGen.value(col),
|
|
2116
2139
|
draggable: unref(isHeaderDraggable)(col) ? "true" : "false",
|
|
2117
2140
|
rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
|
|
@@ -2120,7 +2143,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2120
2143
|
title: getHeaderTitle(col),
|
|
2121
2144
|
class: normalizeClass([
|
|
2122
2145
|
col.sorter ? "sortable" : "",
|
|
2123
|
-
col
|
|
2146
|
+
colKeyGen.value(col) === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
|
|
2124
2147
|
col.headerClassName,
|
|
2125
2148
|
unref(fixedColClassMap).get(colKeyGen.value(col))
|
|
2126
2149
|
]),
|
|
@@ -2191,7 +2214,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2191
2214
|
unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_7)) : createCommentVNode("", true),
|
|
2192
2215
|
_ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
|
|
2193
2216
|
return openBlock(), createElementBlock("td", {
|
|
2194
|
-
key: col
|
|
2217
|
+
key: colKeyGen.value(col),
|
|
2195
2218
|
style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col)))
|
|
2196
2219
|
}, null, 4);
|
|
2197
2220
|
}), 128)) : createCommentVNode("", true)
|
|
@@ -2199,16 +2222,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2199
2222
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
|
|
2200
2223
|
var _a, _b;
|
|
2201
2224
|
return openBlock(), createElementBlock("tr", {
|
|
2202
|
-
id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex),
|
|
2225
|
+
id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex),
|
|
2203
2226
|
ref_for: true,
|
|
2204
2227
|
ref_key: "trRef",
|
|
2205
2228
|
ref: trRef,
|
|
2206
|
-
key: _ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex,
|
|
2207
|
-
"data-row-key": _ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex,
|
|
2229
|
+
key: _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
|
|
2230
|
+
"data-row-key": _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
|
|
2208
2231
|
class: normalizeClass({
|
|
2209
2232
|
active: _ctx.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
|
|
2210
2233
|
hover: props.showTrHoverClass && (_ctx.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
|
|
2211
|
-
[_ctx.rowClassName(row, unref(virtualScroll).startIndex + rowIndex)]: true,
|
|
2234
|
+
[_ctx.rowClassName(row, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)]: true,
|
|
2212
2235
|
expanded: row == null ? void 0 : row.__EXPANDED__,
|
|
2213
2236
|
"expanded-row": row && row.__EXPANDED_ROW__
|
|
2214
2237
|
}),
|
|
@@ -2219,7 +2242,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2219
2242
|
onDblclick: (e) => onRowDblclick(e, row),
|
|
2220
2243
|
onContextmenu: (e) => onRowMenu(e, row),
|
|
2221
2244
|
onMouseover: (e) => onTrMouseOver(e, row),
|
|
2222
|
-
onDrop: (e) => unref(onTrDrop)(e, unref(virtualScroll).startIndex + rowIndex)
|
|
2245
|
+
onDrop: (e) => unref(onTrDrop)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
|
|
2223
2246
|
}, [
|
|
2224
2247
|
unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_9)) : createCommentVNode("", true),
|
|
2225
2248
|
row && row.__EXPANDED_ROW__ ? (openBlock(), createElementBlock("td", {
|
|
@@ -2239,9 +2262,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2239
2262
|
])
|
|
2240
2263
|
], 8, _hoisted_10)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
|
|
2241
2264
|
return openBlock(), createElementBlock("td", {
|
|
2242
|
-
key: col
|
|
2243
|
-
"data-
|
|
2244
|
-
"cell-key": rowKeyGen(row) + "--" + colKeyGen.value(col),
|
|
2265
|
+
key: colKeyGen.value(col),
|
|
2266
|
+
"data-cell-key": cellKeyGen(row, col),
|
|
2245
2267
|
style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col))),
|
|
2246
2268
|
class: normalizeClass([
|
|
2247
2269
|
col.className,
|
|
@@ -2267,7 +2289,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2267
2289
|
class: "table-cell-wrapper",
|
|
2268
2290
|
col,
|
|
2269
2291
|
row,
|
|
2270
|
-
rowIndex: unref(virtualScroll).startIndex + rowIndex,
|
|
2292
|
+
rowIndex: (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
|
|
2271
2293
|
colIndex,
|
|
2272
2294
|
cellValue: row == null ? void 0 : row[col.dataIndex],
|
|
2273
2295
|
expanded: (row == null ? void 0 : row.__EXPANDED__) || null
|
|
@@ -2277,10 +2299,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2277
2299
|
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
|
|
2278
2300
|
}, [
|
|
2279
2301
|
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2280
|
-
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + unref(virtualScroll).startIndex + rowIndex + 1), 1)
|
|
2302
|
+
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex + 1), 1)
|
|
2281
2303
|
], 64)) : col.type === "expand" ? (openBlock(), createElementBlock("span", _hoisted_14, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2282
2304
|
createVNode(DragHandle, {
|
|
2283
|
-
onDragstart: (e) => unref(onTrDragStart)(e, unref(virtualScroll).startIndex + rowIndex)
|
|
2305
|
+
onDragstart: (e) => unref(onTrDragStart)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
|
|
2284
2306
|
}, null, 8, ["onDragstart"]),
|
|
2285
2307
|
createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
|
|
2286
2308
|
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
|
package/lib/style.css
CHANGED
|
@@ -38,8 +38,6 @@
|
|
|
38
38
|
display:flex;
|
|
39
39
|
flex-direction:column;
|
|
40
40
|
box-sizing:border-box;
|
|
41
|
-
border-left:1px solid #e8e8f4;
|
|
42
|
-
border-left:1px solid var(--border-color);
|
|
43
41
|
background-image:linear-gradient(180deg, #e8e8f4 1px, transparent 1px), linear-gradient(270deg, #e8e8f4 1px, transparent 1px), linear-gradient(0deg, #e8e8f4 1px, transparent 1px);
|
|
44
42
|
background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
|
|
45
43
|
}
|
|
@@ -78,12 +76,8 @@
|
|
|
78
76
|
.stk-table.is-col-resizing th{
|
|
79
77
|
pointer-events:none;
|
|
80
78
|
}
|
|
81
|
-
.stk-table.border
|
|
82
|
-
|
|
83
|
-
--bg-border-left:linear-gradient(transparent, transparent);
|
|
84
|
-
}
|
|
85
|
-
.stk-table.border-v{
|
|
86
|
-
--bg-border-bottom:linear-gradient(transparent, transparent);
|
|
79
|
+
.stk-table.border{
|
|
80
|
+
border-left:1px solid var(--border-color);
|
|
87
81
|
}
|
|
88
82
|
.stk-table.border th,
|
|
89
83
|
.stk-table.border td{
|
|
@@ -92,6 +86,15 @@
|
|
|
92
86
|
.stk-table.border thead tr:first-child th{
|
|
93
87
|
background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
|
|
94
88
|
}
|
|
89
|
+
.stk-table.border-h{
|
|
90
|
+
border-left:none;
|
|
91
|
+
--bg-border-right:linear-gradient(transparent, transparent);
|
|
92
|
+
--bg-border-left:linear-gradient(transparent, transparent);
|
|
93
|
+
}
|
|
94
|
+
.stk-table.border-v{
|
|
95
|
+
--bg-border-bottom:linear-gradient(transparent, transparent);
|
|
96
|
+
--bg-border-top:linear-gradient(transparent, transparent);
|
|
97
|
+
}
|
|
95
98
|
.stk-table.border-body-v tbody{
|
|
96
99
|
--bg-border-bottom:linear-gradient(transparent, transparent);
|
|
97
100
|
}
|