stk-table-vue 0.8.9 → 0.8.11
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/lib/src/StkTable/StkTable.vue.d.ts +2 -2
- package/lib/src/StkTable/types/index.d.ts +8 -6
- package/lib/stk-table-vue.js +92 -112
- package/package.json +2 -2
- package/src/StkTable/StkTable.vue +96 -115
- package/src/StkTable/types/index.ts +8 -6
- package/src/StkTable/useRowExpand.ts +4 -4
- package/src/StkTable/useTree.ts +13 -17
|
@@ -214,7 +214,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
214
214
|
rowHeight: number;
|
|
215
215
|
autoRowHeight: boolean;
|
|
216
216
|
rowHover: boolean;
|
|
217
|
-
rowActive:
|
|
217
|
+
rowActive: () => Required<RowActiveOption<any>>;
|
|
218
218
|
rowCurrentRevokable: boolean;
|
|
219
219
|
headerRowHeight: number;
|
|
220
220
|
virtual: boolean;
|
|
@@ -583,7 +583,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
583
583
|
rowHeight: number;
|
|
584
584
|
autoRowHeight: boolean;
|
|
585
585
|
rowHover: boolean;
|
|
586
|
-
rowActive:
|
|
586
|
+
rowActive: () => Required<RowActiveOption<any>>;
|
|
587
587
|
rowCurrentRevokable: boolean;
|
|
588
588
|
headerRowHeight: number;
|
|
589
589
|
virtual: boolean;
|
|
@@ -18,7 +18,9 @@ export type CustomCellProps<T extends Record<string, any>> = {
|
|
|
18
18
|
* - 不展开: null
|
|
19
19
|
* - 展开: 返回column配置
|
|
20
20
|
*/
|
|
21
|
-
expanded
|
|
21
|
+
expanded: PrivateRowDT['__EXP__'];
|
|
22
|
+
/** if tree expanded */
|
|
23
|
+
treeExpanded: PrivateRowDT['__T_EXP__'];
|
|
22
24
|
};
|
|
23
25
|
export type CustomHeaderCellProps<T extends Record<string, any>> = {
|
|
24
26
|
col: StkTableColumn<T>;
|
|
@@ -134,25 +136,25 @@ export type PrivateRowDT = {
|
|
|
134
136
|
/**
|
|
135
137
|
* Only expanded row will add this key
|
|
136
138
|
*
|
|
137
|
-
* If user define the `
|
|
139
|
+
* If user define the `__ROW_K__` in table data, this value will be used as the row key
|
|
138
140
|
* @private
|
|
139
141
|
*/
|
|
140
|
-
|
|
142
|
+
__ROW_K__?: string;
|
|
141
143
|
/**
|
|
142
144
|
* if row expanded
|
|
143
145
|
* @private
|
|
144
146
|
*/
|
|
145
|
-
|
|
147
|
+
__EXP__?: StkTableColumn<any> | null;
|
|
146
148
|
/**
|
|
147
149
|
* if tree node row expanded
|
|
148
150
|
* @private
|
|
149
151
|
*/
|
|
150
|
-
|
|
152
|
+
__T_EXP__?: boolean;
|
|
151
153
|
/**
|
|
152
154
|
* tree parent key
|
|
153
155
|
* @private
|
|
154
156
|
*/
|
|
155
|
-
|
|
157
|
+
__T_P_K__?: UniqKey;
|
|
156
158
|
/**
|
|
157
159
|
* tree level
|
|
158
160
|
* @private
|
package/lib/stk-table-vue.js
CHANGED
|
@@ -971,7 +971,7 @@ function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, v
|
|
|
971
971
|
};
|
|
972
972
|
}
|
|
973
973
|
function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
|
|
974
|
-
const expandedKey = "
|
|
974
|
+
const expandedKey = "__EXP__";
|
|
975
975
|
function isExpanded(row, col) {
|
|
976
976
|
return (row == null ? void 0 : row[expandedKey]) === col ? !(row == null ? void 0 : row[expandedKey]) : true;
|
|
977
977
|
}
|
|
@@ -994,7 +994,7 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
|
|
|
994
994
|
}
|
|
995
995
|
for (let i = index + 1; i < tempData.length; i++) {
|
|
996
996
|
const item = tempData[i];
|
|
997
|
-
const rowKey2 = item.
|
|
997
|
+
const rowKey2 = item.__ROW_K__;
|
|
998
998
|
if (rowKey2 == null ? void 0 : rowKey2.startsWith(EXPANDED_ROW_KEY_PREFIX)) {
|
|
999
999
|
tempData.splice(i, 1);
|
|
1000
1000
|
i--;
|
|
@@ -1009,14 +1009,14 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1009
1009
|
}
|
|
1010
1010
|
if (expand) {
|
|
1011
1011
|
const newExpandRow = {
|
|
1012
|
-
|
|
1012
|
+
__ROW_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
|
|
1013
1013
|
__EXPANDED_ROW__: row,
|
|
1014
1014
|
__EXPANDED_COL__: col
|
|
1015
1015
|
};
|
|
1016
1016
|
tempData.splice(index + 1, 0, newExpandRow);
|
|
1017
1017
|
}
|
|
1018
1018
|
if (row) {
|
|
1019
|
-
row.
|
|
1019
|
+
row.__EXP__ = expand ? col : null;
|
|
1020
1020
|
}
|
|
1021
1021
|
dataSourceCopy.value = tempData;
|
|
1022
1022
|
if (!(data == null ? void 0 : data.silent)) {
|
|
@@ -1253,7 +1253,7 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
|
|
|
1253
1253
|
function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
1254
1254
|
const { defaultExpandAll, defaultExpandKeys, defaultExpandLevel } = props.treeConfig;
|
|
1255
1255
|
function toggleTreeNode(row, col) {
|
|
1256
|
-
const expand = row ? !row.
|
|
1256
|
+
const expand = row ? !row.__T_EXP__ : false;
|
|
1257
1257
|
privateSetTreeExpand(row, { expand, col, isClick: true });
|
|
1258
1258
|
}
|
|
1259
1259
|
function privateSetTreeExpand(row, option) {
|
|
@@ -1276,7 +1276,7 @@ function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1276
1276
|
const level = row2.__T_LV__ || 0;
|
|
1277
1277
|
let expanded = option == null ? void 0 : option.expand;
|
|
1278
1278
|
if (expanded === void 0) {
|
|
1279
|
-
expanded = !row2.
|
|
1279
|
+
expanded = !row2.__T_EXP__;
|
|
1280
1280
|
}
|
|
1281
1281
|
if (expanded) {
|
|
1282
1282
|
const children = expandNode(row2, level);
|
|
@@ -1296,13 +1296,10 @@ function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1296
1296
|
privateSetTreeExpand(row, { ...option, isClick: false });
|
|
1297
1297
|
}
|
|
1298
1298
|
function setNodeExpanded(row, expanded, level, parent) {
|
|
1299
|
-
row.
|
|
1299
|
+
row.__T_EXP__ = expanded;
|
|
1300
1300
|
if (level !== void 0) {
|
|
1301
1301
|
row.__T_LV__ = level;
|
|
1302
1302
|
}
|
|
1303
|
-
if (parent) {
|
|
1304
|
-
row.__T_PARENT_K__ = rowKeyGen(parent);
|
|
1305
|
-
}
|
|
1306
1303
|
}
|
|
1307
1304
|
function flatTreeData(data) {
|
|
1308
1305
|
const result = [];
|
|
@@ -1311,28 +1308,24 @@ function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1311
1308
|
for (let i = 0; i < data2.length; i++) {
|
|
1312
1309
|
const item = data2[i];
|
|
1313
1310
|
result.push(item);
|
|
1314
|
-
const isExpanded = Boolean(item.
|
|
1315
|
-
setNodeExpanded(item, isExpanded, level
|
|
1311
|
+
const isExpanded = Boolean(item.__T_EXP__);
|
|
1312
|
+
setNodeExpanded(item, isExpanded, level);
|
|
1316
1313
|
if (!isExpanded) {
|
|
1317
1314
|
if (defaultExpandAll) {
|
|
1318
1315
|
setNodeExpanded(item, true);
|
|
1319
1316
|
} else {
|
|
1320
|
-
if (defaultExpandLevel) {
|
|
1321
|
-
|
|
1322
|
-
setNodeExpanded(item, true);
|
|
1323
|
-
}
|
|
1317
|
+
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
1318
|
+
setNodeExpanded(item, true);
|
|
1324
1319
|
}
|
|
1325
|
-
if (defaultExpandKeys) {
|
|
1326
|
-
|
|
1327
|
-
setNodeExpanded(item, true);
|
|
1328
|
-
}
|
|
1320
|
+
if (defaultExpandKeys == null ? void 0 : defaultExpandKeys.includes(rowKeyGen(item))) {
|
|
1321
|
+
setNodeExpanded(item, true);
|
|
1329
1322
|
}
|
|
1330
|
-
if (!item.
|
|
1323
|
+
if (!item.__T_EXP__) {
|
|
1331
1324
|
continue;
|
|
1332
1325
|
}
|
|
1333
1326
|
}
|
|
1334
1327
|
}
|
|
1335
|
-
recursion(item.children, level + 1
|
|
1328
|
+
recursion(item.children, level + 1);
|
|
1336
1329
|
}
|
|
1337
1330
|
})(data, 0);
|
|
1338
1331
|
return result;
|
|
@@ -1342,11 +1335,11 @@ function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1342
1335
|
row.children && row.children.forEach((child) => {
|
|
1343
1336
|
result.push(child);
|
|
1344
1337
|
const childLv = level + 1;
|
|
1345
|
-
if (child.
|
|
1338
|
+
if (child.__T_EXP__ && child.children) {
|
|
1346
1339
|
const res = expandNode(child, childLv);
|
|
1347
1340
|
result = result.concat(res);
|
|
1348
1341
|
} else {
|
|
1349
|
-
setNodeExpanded(child, false, childLv
|
|
1342
|
+
setNodeExpanded(child, false, childLv);
|
|
1350
1343
|
}
|
|
1351
1344
|
});
|
|
1352
1345
|
return result;
|
|
@@ -1726,7 +1719,6 @@ const _hoisted_9 = ["colspan"];
|
|
|
1726
1719
|
const _hoisted_10 = { class: "table-cell-wrapper" };
|
|
1727
1720
|
const _hoisted_11 = ["data-cell-key", "onClick", "onMousedown", "onMouseenter", "onMouseleave", "onMouseover"];
|
|
1728
1721
|
const _hoisted_12 = ["title"];
|
|
1729
|
-
const _hoisted_13 = ["title"];
|
|
1730
1722
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1731
1723
|
__name: "StkTable",
|
|
1732
1724
|
props: {
|
|
@@ -1740,7 +1732,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1740
1732
|
rowHeight: { default: DEFAULT_ROW_HEIGHT },
|
|
1741
1733
|
autoRowHeight: { type: Boolean, default: false },
|
|
1742
1734
|
rowHover: { type: Boolean, default: true },
|
|
1743
|
-
rowActive: { type: Boolean, default:
|
|
1735
|
+
rowActive: { type: Boolean, default: () => DEFAULT_ROW_ACTIVE_CONFIG },
|
|
1744
1736
|
rowCurrentRevokable: { type: Boolean, default: true },
|
|
1745
1737
|
headerRowHeight: { default: DEFAULT_ROW_HEIGHT },
|
|
1746
1738
|
virtual: { type: Boolean, default: false },
|
|
@@ -1806,7 +1798,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1806
1798
|
if (typeof rowActive === "boolean") {
|
|
1807
1799
|
return {
|
|
1808
1800
|
...DEFAULT_ROW_ACTIVE_CONFIG,
|
|
1809
|
-
enabled: rowActive,
|
|
1801
|
+
enabled: rowActive ?? true,
|
|
1810
1802
|
revokable: Boolean(props.rowCurrentRevokable)
|
|
1811
1803
|
};
|
|
1812
1804
|
} else {
|
|
@@ -1959,27 +1951,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1959
1951
|
);
|
|
1960
1952
|
watch(
|
|
1961
1953
|
() => props.dataSource,
|
|
1962
|
-
(val) =>
|
|
1963
|
-
if (!Array.isArray(val)) {
|
|
1964
|
-
console.warn("invalid dataSource");
|
|
1965
|
-
return;
|
|
1966
|
-
}
|
|
1967
|
-
let needInitVirtualScrollY = false;
|
|
1968
|
-
if (dataSourceCopy.value.length !== val.length) {
|
|
1969
|
-
needInitVirtualScrollY = true;
|
|
1970
|
-
}
|
|
1971
|
-
initDataSource(val);
|
|
1972
|
-
updateMaxRowSpan();
|
|
1973
|
-
if (needInitVirtualScrollY) {
|
|
1974
|
-
nextTick(() => initVirtualScrollY());
|
|
1975
|
-
}
|
|
1976
|
-
const sortColValue = sortCol.value;
|
|
1977
|
-
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
1978
|
-
const colKey = colKeyGen.value;
|
|
1979
|
-
const column = tableHeaderLast.value.find((it) => colKey(it) === sortColValue);
|
|
1980
|
-
onColumnSort(column, false);
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1954
|
+
(val) => updateDataSource(val)
|
|
1983
1955
|
);
|
|
1984
1956
|
watch(
|
|
1985
1957
|
() => props.fixedColShadow,
|
|
@@ -2074,13 +2046,34 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2074
2046
|
tableHeaders.value = tableHeadersTemp;
|
|
2075
2047
|
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
2076
2048
|
}
|
|
2049
|
+
function updateDataSource(val) {
|
|
2050
|
+
if (!Array.isArray(val)) {
|
|
2051
|
+
console.warn("invalid dataSource");
|
|
2052
|
+
return;
|
|
2053
|
+
}
|
|
2054
|
+
let needInitVirtualScrollY = false;
|
|
2055
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
2056
|
+
needInitVirtualScrollY = true;
|
|
2057
|
+
}
|
|
2058
|
+
initDataSource(val);
|
|
2059
|
+
updateMaxRowSpan();
|
|
2060
|
+
if (needInitVirtualScrollY) {
|
|
2061
|
+
nextTick(() => initVirtualScrollY());
|
|
2062
|
+
}
|
|
2063
|
+
const sortColValue = sortCol.value;
|
|
2064
|
+
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
2065
|
+
const colKey = colKeyGen.value;
|
|
2066
|
+
const column = tableHeaderLast.value.find((it) => colKey(it) === sortColValue);
|
|
2067
|
+
onColumnSort(column, false);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2077
2070
|
function rowKeyGen(row) {
|
|
2078
2071
|
if (!row) return row;
|
|
2079
|
-
let key = rowKeyGenCache.get(row) || row.
|
|
2072
|
+
let key = rowKeyGenCache.get(row) || row.__ROW_K__;
|
|
2080
2073
|
if (!key) {
|
|
2081
2074
|
key = rowKeyGenComputed.value(row);
|
|
2082
2075
|
if (key === void 0) {
|
|
2083
|
-
key = Math.random().toString();
|
|
2076
|
+
key = Math.random().toString(36).slice(2);
|
|
2084
2077
|
}
|
|
2085
2078
|
rowKeyGenCache.set(row, key);
|
|
2086
2079
|
}
|
|
@@ -2251,22 +2244,27 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2251
2244
|
}
|
|
2252
2245
|
const dom = tableContainerRef.value;
|
|
2253
2246
|
if (!dom) return;
|
|
2247
|
+
if (!virtual_on.value && !virtualX_on.value) return;
|
|
2254
2248
|
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
2255
2249
|
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
2256
2250
|
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
2257
2251
|
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
2258
|
-
const { deltaY, deltaX } = e;
|
|
2259
|
-
if (virtual_on.value && deltaY) {
|
|
2252
|
+
const { deltaY, deltaX, shiftKey } = e;
|
|
2253
|
+
if (virtual_on.value && deltaY && !shiftKey) {
|
|
2260
2254
|
if (deltaY > 0 && !isScrollBottom || deltaY < 0 && scrollTop > 0) {
|
|
2261
2255
|
e.preventDefault();
|
|
2262
2256
|
}
|
|
2263
2257
|
dom.scrollTop += deltaY;
|
|
2264
2258
|
}
|
|
2265
|
-
if (virtualX_on.value
|
|
2266
|
-
|
|
2259
|
+
if (virtualX_on.value) {
|
|
2260
|
+
let distance = deltaX;
|
|
2261
|
+
if (shiftKey && deltaY) {
|
|
2262
|
+
distance = deltaY;
|
|
2263
|
+
}
|
|
2264
|
+
if (distance > 0 && !isScrollRight || distance < 0 && scrollLeft > 0) {
|
|
2267
2265
|
e.preventDefault();
|
|
2268
2266
|
}
|
|
2269
|
-
dom.scrollLeft +=
|
|
2267
|
+
dom.scrollLeft += distance;
|
|
2270
2268
|
}
|
|
2271
2269
|
}
|
|
2272
2270
|
function onTableScroll(e) {
|
|
@@ -2693,7 +2691,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2693
2691
|
active: _ctx.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
|
|
2694
2692
|
hover: props.showTrHoverClass && (_ctx.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
|
|
2695
2693
|
[_ctx.rowClassName(row, getRowIndex(rowIndex)) || ""]: true,
|
|
2696
|
-
expanded: row == null ? void 0 : row.
|
|
2694
|
+
expanded: row == null ? void 0 : row.__EXP__,
|
|
2697
2695
|
"expanded-row": row && row.__EXPANDED_ROW__
|
|
2698
2696
|
}),
|
|
2699
2697
|
style: normalizeStyle({
|
|
@@ -2737,8 +2735,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2737
2735
|
"cell-active": col.mergeCells && unref(activeMergedCells).has(cellKeyGen(row, col)),
|
|
2738
2736
|
"seq-column": col.type === "seq",
|
|
2739
2737
|
active: props.cellActive && currentSelectedCellKey.value === cellKeyGen(row, col),
|
|
2740
|
-
expanded: col.type === "expand" && (row.
|
|
2741
|
-
"tree-expanded": col.type === "tree-node" && row.
|
|
2738
|
+
expanded: col.type === "expand" && (row.__EXP__ ? colKeyGen.value(row.__EXP__) === colKeyGen.value(col) : false),
|
|
2739
|
+
"tree-expanded": col.type === "tree-node" && row.__T_EXP__,
|
|
2742
2740
|
"drag-row-cell": col.type === "dragRow"
|
|
2743
2741
|
}
|
|
2744
2742
|
]
|
|
@@ -2749,27 +2747,42 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2749
2747
|
onMouseleave: ($event) => onCellMouseLeave($event, row, col),
|
|
2750
2748
|
onMouseover: ($event) => onCellMouseOver($event, row, col)
|
|
2751
2749
|
}), [
|
|
2752
|
-
col.
|
|
2750
|
+
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
2753
2751
|
key: 0,
|
|
2754
2752
|
class: "table-cell-wrapper",
|
|
2755
|
-
|
|
2756
|
-
|
|
2753
|
+
col,
|
|
2754
|
+
row,
|
|
2755
|
+
rowIndex: getRowIndex(rowIndex),
|
|
2756
|
+
colIndex,
|
|
2757
|
+
cellValue: row && row[col.dataIndex],
|
|
2758
|
+
expanded: row ? row.__EXP_ : null,
|
|
2759
|
+
"tree-expanded": row ? row.__T_EXP__ : null
|
|
2760
|
+
}, {
|
|
2761
|
+
stkFoldIcon: withCtx(() => [
|
|
2762
|
+
createVNode(TriangleIcon, {
|
|
2763
|
+
onClick: ($event) => triangleClick($event, row, col)
|
|
2764
|
+
}, null, 8, ["onClick"])
|
|
2765
|
+
]),
|
|
2766
|
+
stkDragIcon: withCtx(() => [
|
|
2767
|
+
createVNode(DragHandle, {
|
|
2768
|
+
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2769
|
+
}, null, 8, ["onDragstart"])
|
|
2770
|
+
]),
|
|
2771
|
+
_: 2
|
|
2772
|
+
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue", "expanded", "tree-expanded"])) : (openBlock(), createElementBlock("div", {
|
|
2773
|
+
key: 1,
|
|
2774
|
+
class: "table-cell-wrapper",
|
|
2775
|
+
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : "",
|
|
2776
|
+
style: normalizeStyle(col.type === "tree-node" ? { paddingLeft: row.__T_LV__ && row.__T_LV__ * 16 + "px" } : {})
|
|
2757
2777
|
}, [
|
|
2758
|
-
col.
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
"tree-expanded": row && row.__T_EXPANDED__ || null
|
|
2767
|
-
}, {
|
|
2768
|
-
stkFoldIcon: withCtx(() => [
|
|
2769
|
-
createVNode(TriangleIcon)
|
|
2770
|
-
]),
|
|
2771
|
-
_: 2
|
|
2772
|
-
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue", "expanded", "tree-expanded"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2778
|
+
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2779
|
+
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
|
|
2780
|
+
], 64)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2781
|
+
createVNode(DragHandle, {
|
|
2782
|
+
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2783
|
+
}, null, 8, ["onDragstart"]),
|
|
2784
|
+
createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
|
|
2785
|
+
], 64)) : col.type === "expand" || col.type === "tree-node" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2773
2786
|
col.type === "expand" || col.type === "tree-node" && row.children !== void 0 ? (openBlock(), createBlock(TriangleIcon, {
|
|
2774
2787
|
key: 0,
|
|
2775
2788
|
onClick: ($event) => triangleClick($event, row, col)
|
|
@@ -2777,43 +2790,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2777
2790
|
createElementVNode("span", {
|
|
2778
2791
|
style: normalizeStyle(col.type === "tree-node" && !row.children ? "padding-left: 16px;" : "")
|
|
2779
2792
|
}, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 5)
|
|
2793
|
+
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
|
|
2794
|
+
createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
|
|
2780
2795
|
], 64))
|
|
2781
|
-
], 12, _hoisted_12))
|
|
2782
|
-
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
2783
|
-
key: 0,
|
|
2784
|
-
class: "table-cell-wrapper",
|
|
2785
|
-
col,
|
|
2786
|
-
row,
|
|
2787
|
-
rowIndex: getRowIndex(rowIndex),
|
|
2788
|
-
colIndex,
|
|
2789
|
-
cellValue: row && row[col.dataIndex]
|
|
2790
|
-
}, {
|
|
2791
|
-
stkFoldIcon: withCtx(() => [
|
|
2792
|
-
createVNode(TriangleIcon)
|
|
2793
|
-
]),
|
|
2794
|
-
stkDragIcon: withCtx(() => [
|
|
2795
|
-
createVNode(DragHandle, {
|
|
2796
|
-
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2797
|
-
}, null, 8, ["onDragstart"])
|
|
2798
|
-
]),
|
|
2799
|
-
_: 2
|
|
2800
|
-
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue"])) : (openBlock(), createElementBlock("div", {
|
|
2801
|
-
key: 1,
|
|
2802
|
-
class: "table-cell-wrapper",
|
|
2803
|
-
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
|
|
2804
|
-
}, [
|
|
2805
|
-
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2806
|
-
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
|
|
2807
|
-
], 64)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2808
|
-
createVNode(DragHandle, {
|
|
2809
|
-
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2810
|
-
}, null, 8, ["onDragstart"]),
|
|
2811
|
-
createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
|
|
2812
|
-
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2813
|
-
createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
|
|
2814
|
-
], 64))
|
|
2815
|
-
], 8, _hoisted_13))
|
|
2816
|
-
], 64))
|
|
2796
|
+
], 12, _hoisted_12))
|
|
2817
2797
|
], 16, _hoisted_11)) : createCommentVNode("", true)
|
|
2818
2798
|
], 64);
|
|
2819
2799
|
}), 256))
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stk-table-vue",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.11",
|
|
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",
|
|
7
7
|
"packageManager": "pnpm@10.7.0",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
active: rowKey ? rowKeyGen(row) === currentRowKey : row === currentRow,
|
|
116
116
|
hover: props.showTrHoverClass && (rowKey ? rowKeyGen(row) === currentHoverRowKey : row === currentHoverRowKey),
|
|
117
117
|
[rowClassName(row, getRowIndex(rowIndex)) || '']: true,
|
|
118
|
-
expanded: row?.
|
|
118
|
+
expanded: row?.__EXP__,
|
|
119
119
|
'expanded-row': row && row.__EXPANDED_ROW__,
|
|
120
120
|
}"
|
|
121
121
|
:style="{
|
|
@@ -152,9 +152,8 @@
|
|
|
152
152
|
'cell-active': col.mergeCells && activeMergedCells.has(cellKeyGen(row, col)),
|
|
153
153
|
'seq-column': col.type === 'seq',
|
|
154
154
|
active: props.cellActive && currentSelectedCellKey === cellKeyGen(row, col),
|
|
155
|
-
expanded:
|
|
156
|
-
|
|
157
|
-
'tree-expanded': col.type === 'tree-node' && row.__T_EXPANDED__,
|
|
155
|
+
expanded: col.type === 'expand' && (row.__EXP__ ? colKeyGen(row.__EXP__) === colKeyGen(col) : false),
|
|
156
|
+
'tree-expanded': col.type === 'tree-node' && row.__T_EXP__,
|
|
158
157
|
'drag-row-cell': col.type === 'dragRow',
|
|
159
158
|
},
|
|
160
159
|
]"
|
|
@@ -165,71 +164,53 @@
|
|
|
165
164
|
@mouseleave="onCellMouseLeave($event, row, col)"
|
|
166
165
|
@mouseover="onCellMouseOver($event, row, col)"
|
|
167
166
|
>
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
>
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
216
|
-
</template>
|
|
217
|
-
</component>
|
|
218
|
-
<div v-else class="table-cell-wrapper" :title="col.type !== 'seq' ? row?.[col.dataIndex] : ''">
|
|
219
|
-
<template v-if="col.type === 'seq'">
|
|
220
|
-
{{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
|
|
221
|
-
</template>
|
|
222
|
-
<template v-else-if="col.type === 'dragRow'">
|
|
223
|
-
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
224
|
-
<span>
|
|
225
|
-
{{ row?.[col.dataIndex] ?? '' }}
|
|
226
|
-
</span>
|
|
227
|
-
</template>
|
|
228
|
-
<template v-else>
|
|
229
|
-
{{ row?.[col.dataIndex] ?? getEmptyCellText(col, row) }}
|
|
230
|
-
</template>
|
|
231
|
-
</div>
|
|
232
|
-
</template>
|
|
167
|
+
<component
|
|
168
|
+
:is="col.customCell"
|
|
169
|
+
v-if="col.customCell"
|
|
170
|
+
class="table-cell-wrapper"
|
|
171
|
+
:col="col"
|
|
172
|
+
:row="row"
|
|
173
|
+
:rowIndex="getRowIndex(rowIndex)"
|
|
174
|
+
:colIndex="colIndex"
|
|
175
|
+
:cellValue="row && row[col.dataIndex]"
|
|
176
|
+
:expanded="row ? row.__EXP_ : null"
|
|
177
|
+
:tree-expanded="row ? row.__T_EXP__ : null"
|
|
178
|
+
>
|
|
179
|
+
<template #stkFoldIcon>
|
|
180
|
+
<TriangleIcon @click="triangleClick($event, row, col)"></TriangleIcon>
|
|
181
|
+
</template>
|
|
182
|
+
<template #stkDragIcon>
|
|
183
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
184
|
+
</template>
|
|
185
|
+
</component>
|
|
186
|
+
<div
|
|
187
|
+
v-else
|
|
188
|
+
class="table-cell-wrapper"
|
|
189
|
+
:title="col.type !== 'seq' ? row?.[col.dataIndex] : ''"
|
|
190
|
+
:style="col.type === 'tree-node' ? { paddingLeft: row.__T_LV__ && row.__T_LV__ * 16 + 'px' } : {}"
|
|
191
|
+
>
|
|
192
|
+
<template v-if="col.type === 'seq'">
|
|
193
|
+
{{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
|
|
194
|
+
</template>
|
|
195
|
+
<template v-else-if="col.type === 'dragRow'">
|
|
196
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
197
|
+
<span>
|
|
198
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
199
|
+
</span>
|
|
200
|
+
</template>
|
|
201
|
+
<template v-else-if="col.type === 'expand' || col.type === 'tree-node'">
|
|
202
|
+
<TriangleIcon
|
|
203
|
+
v-if="col.type === 'expand' || (col.type === 'tree-node' && row.children !== void 0)"
|
|
204
|
+
@click="triangleClick($event, row, col)"
|
|
205
|
+
/>
|
|
206
|
+
<span :style="col.type === 'tree-node' && !row.children ? 'padding-left: 16px;' : ''">
|
|
207
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
208
|
+
</span>
|
|
209
|
+
</template>
|
|
210
|
+
<template v-else>
|
|
211
|
+
{{ row?.[col.dataIndex] ?? getEmptyCellText(col, row) }}
|
|
212
|
+
</template>
|
|
213
|
+
</div>
|
|
233
214
|
</td>
|
|
234
215
|
</template>
|
|
235
216
|
</template>
|
|
@@ -456,7 +437,7 @@ const props = withDefaults(
|
|
|
456
437
|
rowHeight: DEFAULT_ROW_HEIGHT,
|
|
457
438
|
autoRowHeight: false,
|
|
458
439
|
rowHover: true,
|
|
459
|
-
rowActive:
|
|
440
|
+
rowActive: () => DEFAULT_ROW_ACTIVE_CONFIG,
|
|
460
441
|
rowCurrentRevokable: true,
|
|
461
442
|
headerRowHeight: DEFAULT_ROW_HEIGHT,
|
|
462
443
|
virtual: false,
|
|
@@ -721,7 +702,7 @@ const rowActiveProp = computed<Required<RowActiveOption<DT>>>(() => {
|
|
|
721
702
|
if (typeof rowActive === 'boolean') {
|
|
722
703
|
return {
|
|
723
704
|
...DEFAULT_ROW_ACTIVE_CONFIG,
|
|
724
|
-
enabled: rowActive,
|
|
705
|
+
enabled: rowActive ?? true,
|
|
725
706
|
revokable: Boolean(props.rowCurrentRevokable),
|
|
726
707
|
};
|
|
727
708
|
} else {
|
|
@@ -905,31 +886,7 @@ watch(
|
|
|
905
886
|
|
|
906
887
|
watch(
|
|
907
888
|
() => props.dataSource,
|
|
908
|
-
val =>
|
|
909
|
-
if (!Array.isArray(val)) {
|
|
910
|
-
console.warn('invalid dataSource');
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
let needInitVirtualScrollY = false;
|
|
915
|
-
if (dataSourceCopy.value.length !== val.length) {
|
|
916
|
-
needInitVirtualScrollY = true;
|
|
917
|
-
}
|
|
918
|
-
initDataSource(val);
|
|
919
|
-
updateMaxRowSpan();
|
|
920
|
-
// if data length is not change, not init virtual scroll
|
|
921
|
-
if (needInitVirtualScrollY) {
|
|
922
|
-
// wait for table render,initVirtualScrollY has get `dom` operation.
|
|
923
|
-
nextTick(() => initVirtualScrollY());
|
|
924
|
-
}
|
|
925
|
-
const sortColValue = sortCol.value;
|
|
926
|
-
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
927
|
-
// sort
|
|
928
|
-
const colKey = colKeyGen.value;
|
|
929
|
-
const column = tableHeaderLast.value.find(it => colKey(it) === sortColValue);
|
|
930
|
-
onColumnSort(column, false);
|
|
931
|
-
}
|
|
932
|
-
},
|
|
889
|
+
val => updateDataSource(val),
|
|
933
890
|
);
|
|
934
891
|
|
|
935
892
|
watch(
|
|
@@ -1058,18 +1015,45 @@ function dealColumns() {
|
|
|
1058
1015
|
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
1059
1016
|
}
|
|
1060
1017
|
|
|
1018
|
+
function updateDataSource(val:DT[]) {
|
|
1019
|
+
if (!Array.isArray(val)) {
|
|
1020
|
+
console.warn('invalid dataSource');
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
let needInitVirtualScrollY = false;
|
|
1025
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
1026
|
+
needInitVirtualScrollY = true;
|
|
1027
|
+
}
|
|
1028
|
+
initDataSource(val);
|
|
1029
|
+
updateMaxRowSpan();
|
|
1030
|
+
// if data length is not change, not init virtual scroll
|
|
1031
|
+
if (needInitVirtualScrollY) {
|
|
1032
|
+
// wait for table render,initVirtualScrollY has get `dom` operation.
|
|
1033
|
+
nextTick(() => initVirtualScrollY());
|
|
1034
|
+
}
|
|
1035
|
+
const sortColValue = sortCol.value;
|
|
1036
|
+
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
1037
|
+
// sort
|
|
1038
|
+
const colKey = colKeyGen.value;
|
|
1039
|
+
const column = tableHeaderLast.value.find(it => colKey(it) === sortColValue);
|
|
1040
|
+
onColumnSort(column, false);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
|
|
1061
1045
|
/**
|
|
1062
1046
|
* 行唯一值生成
|
|
1063
1047
|
*/
|
|
1064
1048
|
function rowKeyGen(row: DT | null | undefined) {
|
|
1065
1049
|
if (!row) return row;
|
|
1066
|
-
let key = rowKeyGenCache.get(row) || (row as PrivateRowDT).
|
|
1050
|
+
let key = rowKeyGenCache.get(row) || (row as PrivateRowDT).__ROW_K__;
|
|
1067
1051
|
if (!key) {
|
|
1068
1052
|
key = rowKeyGenComputed.value(row);
|
|
1069
1053
|
|
|
1070
1054
|
if (key === void 0) {
|
|
1071
1055
|
// key为undefined时,不应该高亮行。因此重新生成key
|
|
1072
|
-
key = Math.random().toString();
|
|
1056
|
+
key = Math.random().toString(36).slice(2);
|
|
1073
1057
|
}
|
|
1074
1058
|
rowKeyGenCache.set(row, key);
|
|
1075
1059
|
}
|
|
@@ -1301,50 +1285,47 @@ function onCellMouseDown(e: MouseEvent, row: DT, col: StkTableColumn<DT>, rowInd
|
|
|
1301
1285
|
}
|
|
1302
1286
|
|
|
1303
1287
|
/**
|
|
1304
|
-
*
|
|
1288
|
+
* proxy scroll, prevent white screen
|
|
1305
1289
|
* @param e
|
|
1306
1290
|
*/
|
|
1307
1291
|
function onTableWheel(e: WheelEvent) {
|
|
1308
1292
|
if (props.smoothScroll) {
|
|
1309
1293
|
return;
|
|
1310
1294
|
}
|
|
1295
|
+
// if is resizing, not allow scroll
|
|
1311
1296
|
if (isColResizing.value) {
|
|
1312
|
-
// 正在调整列宽时,不允许用户滚动
|
|
1313
1297
|
e.stopPropagation();
|
|
1314
1298
|
return;
|
|
1315
1299
|
}
|
|
1316
|
-
// #region ---- 控制滚动,防止出现白屏--
|
|
1317
1300
|
const dom = tableContainerRef.value;
|
|
1318
1301
|
if (!dom) return;
|
|
1302
|
+
if (!virtual_on.value && !virtualX_on.value) return;
|
|
1303
|
+
|
|
1319
1304
|
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
1320
1305
|
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
1321
|
-
/** 是否滚动在下面 */
|
|
1322
1306
|
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
1323
|
-
/** 是否滚动在右侧 */
|
|
1324
1307
|
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
1325
|
-
const { deltaY, deltaX } = e;
|
|
1308
|
+
const { deltaY, deltaX, shiftKey } = e;
|
|
1326
1309
|
|
|
1327
|
-
|
|
1328
|
-
* 只有虚拟滚动时,才要用 wheel 代理scroll,防止滚动过快导致的白屏。
|
|
1329
|
-
* 滚动条在边界情况时,not preventDefault 。因为会阻塞父级滚动条滚动。
|
|
1330
|
-
*/
|
|
1331
|
-
if (virtual_on.value && deltaY) {
|
|
1310
|
+
if (virtual_on.value && deltaY && !shiftKey) {
|
|
1332
1311
|
if ((deltaY > 0 && !isScrollBottom) || (deltaY < 0 && scrollTop > 0)) {
|
|
1333
|
-
e.preventDefault();
|
|
1312
|
+
e.preventDefault(); // parent element scroll
|
|
1334
1313
|
}
|
|
1335
1314
|
dom.scrollTop += deltaY;
|
|
1336
1315
|
}
|
|
1337
|
-
if (virtualX_on.value
|
|
1338
|
-
|
|
1316
|
+
if (virtualX_on.value) {
|
|
1317
|
+
let distance = deltaX;
|
|
1318
|
+
if (shiftKey && deltaY) {
|
|
1319
|
+
distance = deltaY;
|
|
1320
|
+
}
|
|
1321
|
+
if ((distance > 0 && !isScrollRight) || (distance < 0 && scrollLeft > 0)) {
|
|
1339
1322
|
e.preventDefault();
|
|
1340
1323
|
}
|
|
1341
|
-
dom.scrollLeft +=
|
|
1324
|
+
dom.scrollLeft += distance;
|
|
1342
1325
|
}
|
|
1343
|
-
//#endregion
|
|
1344
1326
|
}
|
|
1345
1327
|
|
|
1346
1328
|
/**
|
|
1347
|
-
* 滚动条监听
|
|
1348
1329
|
* @param e scrollEvent
|
|
1349
1330
|
*/
|
|
1350
1331
|
function onTableScroll(e: Event) {
|
|
@@ -17,7 +17,9 @@ export type CustomCellProps<T extends Record<string, any>> = {
|
|
|
17
17
|
* - 不展开: null
|
|
18
18
|
* - 展开: 返回column配置
|
|
19
19
|
*/
|
|
20
|
-
expanded
|
|
20
|
+
expanded: PrivateRowDT['__EXP__'];
|
|
21
|
+
/** if tree expanded */
|
|
22
|
+
treeExpanded: PrivateRowDT['__T_EXP__']
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export type CustomHeaderCellProps<T extends Record<string, any>> = {
|
|
@@ -139,25 +141,25 @@ export type PrivateRowDT = {
|
|
|
139
141
|
/**
|
|
140
142
|
* Only expanded row will add this key
|
|
141
143
|
*
|
|
142
|
-
* If user define the `
|
|
144
|
+
* If user define the `__ROW_K__` in table data, this value will be used as the row key
|
|
143
145
|
* @private
|
|
144
146
|
*/
|
|
145
|
-
|
|
147
|
+
__ROW_K__?: string;
|
|
146
148
|
/**
|
|
147
149
|
* if row expanded
|
|
148
150
|
* @private
|
|
149
151
|
*/
|
|
150
|
-
|
|
152
|
+
__EXP__?: StkTableColumn<any> | null;
|
|
151
153
|
/**
|
|
152
154
|
* if tree node row expanded
|
|
153
155
|
* @private
|
|
154
156
|
*/
|
|
155
|
-
|
|
157
|
+
__T_EXP__?: boolean;
|
|
156
158
|
/**
|
|
157
159
|
* tree parent key
|
|
158
160
|
* @private
|
|
159
161
|
*/
|
|
160
|
-
|
|
162
|
+
__T_P_K__?: UniqKey;
|
|
161
163
|
/**
|
|
162
164
|
* tree level
|
|
163
165
|
* @private
|
|
@@ -9,7 +9,7 @@ type Option<DT extends Record<string, any>> = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
12
|
-
const expandedKey = '
|
|
12
|
+
const expandedKey = '__EXP__';
|
|
13
13
|
|
|
14
14
|
function isExpanded(row: DT, col?: StkTableColumn<DT> | null) {
|
|
15
15
|
return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
|
|
@@ -45,7 +45,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
45
45
|
// delete other expanded row below the target row
|
|
46
46
|
for (let i = index + 1; i < tempData.length; i++) {
|
|
47
47
|
const item: PrivateRowDT = tempData[i];
|
|
48
|
-
const rowKey = item.
|
|
48
|
+
const rowKey = item.__ROW_K__;
|
|
49
49
|
if (rowKey?.startsWith(EXPANDED_ROW_KEY_PREFIX)) {
|
|
50
50
|
tempData.splice(i, 1);
|
|
51
51
|
i--;
|
|
@@ -64,7 +64,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
64
64
|
if (expand) {
|
|
65
65
|
// insert new expanded row
|
|
66
66
|
const newExpandRow: ExpandedRow = {
|
|
67
|
-
|
|
67
|
+
__ROW_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
|
|
68
68
|
__EXPANDED_ROW__: row,
|
|
69
69
|
__EXPANDED_COL__: col,
|
|
70
70
|
};
|
|
@@ -72,7 +72,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (row) {
|
|
75
|
-
row.
|
|
75
|
+
row.__EXP__ = expand ? col : null;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
dataSourceCopy.value = tempData;
|
package/src/StkTable/useTree.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
14
14
|
|
|
15
15
|
/** click expended icon to toggle expand row */
|
|
16
16
|
function toggleTreeNode(row: DT, col: any) {
|
|
17
|
-
const expand = row ? !row.
|
|
17
|
+
const expand = row ? !row.__T_EXP__ : false;
|
|
18
18
|
privateSetTreeExpand(row, { expand, col, isClick: true });
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -47,7 +47,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
47
47
|
const level = row.__T_LV__ || 0;
|
|
48
48
|
let expanded = option?.expand;
|
|
49
49
|
if (expanded === void 0) {
|
|
50
|
-
expanded = !row.
|
|
50
|
+
expanded = !row.__T_EXP__;
|
|
51
51
|
}
|
|
52
52
|
if (expanded) {
|
|
53
53
|
const children = expandNode(row, level);
|
|
@@ -73,13 +73,13 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function setNodeExpanded(row: DT, expanded: boolean, level?: number, parent?: DT) {
|
|
76
|
-
row.
|
|
76
|
+
row.__T_EXP__ = expanded;
|
|
77
77
|
if (level !== void 0) {
|
|
78
78
|
row.__T_LV__ = level;
|
|
79
79
|
}
|
|
80
|
-
if (parent) {
|
|
81
|
-
|
|
82
|
-
}
|
|
80
|
+
// if (parent) {
|
|
81
|
+
// row.__T_P_K__ = rowKeyGen(parent);
|
|
82
|
+
// }
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -94,23 +94,19 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
94
94
|
for (let i = 0; i < data.length; i++) {
|
|
95
95
|
const item = data[i];
|
|
96
96
|
result.push(item);
|
|
97
|
-
const isExpanded = Boolean(item.
|
|
97
|
+
const isExpanded = Boolean(item.__T_EXP__);
|
|
98
98
|
setNodeExpanded(item, isExpanded, level, parent);
|
|
99
99
|
if (!isExpanded) {
|
|
100
100
|
if (defaultExpandAll) {
|
|
101
101
|
setNodeExpanded(item, true);
|
|
102
102
|
} else {
|
|
103
|
-
if (defaultExpandLevel) {
|
|
104
|
-
|
|
105
|
-
setNodeExpanded(item, true);
|
|
106
|
-
}
|
|
103
|
+
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
104
|
+
setNodeExpanded(item, true);
|
|
107
105
|
}
|
|
108
|
-
if (defaultExpandKeys) {
|
|
109
|
-
|
|
110
|
-
setNodeExpanded(item, true);
|
|
111
|
-
}
|
|
106
|
+
if (defaultExpandKeys?.includes(rowKeyGen(item))) {
|
|
107
|
+
setNodeExpanded(item, true);
|
|
112
108
|
}
|
|
113
|
-
if (!item.
|
|
109
|
+
if (!item.__T_EXP__) {
|
|
114
110
|
continue;
|
|
115
111
|
}
|
|
116
112
|
}
|
|
@@ -127,7 +123,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
127
123
|
row.children.forEach((child: DT) => {
|
|
128
124
|
result.push(child);
|
|
129
125
|
const childLv = level + 1;
|
|
130
|
-
if (child.
|
|
126
|
+
if (child.__T_EXP__ && child.children) {
|
|
131
127
|
const res = expandNode(child, childLv);
|
|
132
128
|
result = result.concat(res);
|
|
133
129
|
} else {
|