stk-table-vue 0.6.15 → 0.6.17
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/stk-table-vue.js +26 -16
- package/package.json +1 -1
- package/src/StkTable/useVirtualScroll.ts +18 -11
- package/src/StkTable/utils/index.ts +11 -11
package/lib/stk-table-vue.js
CHANGED
|
@@ -64,17 +64,18 @@ function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {})
|
|
|
64
64
|
data.unshift(newItem);
|
|
65
65
|
return data;
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
const targetVal = newItem[dataIndex];
|
|
68
|
+
if (sortConfig.emptyToBottom && isEmptyValue(targetVal)) {
|
|
68
69
|
data.push(newItem);
|
|
70
|
+
} else {
|
|
71
|
+
const isNumber = sortType === "number";
|
|
72
|
+
const sIndex = binarySearch(data, (midIndex) => {
|
|
73
|
+
const midVal = data[midIndex][dataIndex];
|
|
74
|
+
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
75
|
+
return order === "asc" ? compareRes : -compareRes;
|
|
76
|
+
});
|
|
77
|
+
data.splice(sIndex, 0, newItem);
|
|
69
78
|
}
|
|
70
|
-
const isNumber = sortType === "number";
|
|
71
|
-
const targetVal = newItem[dataIndex];
|
|
72
|
-
const sIndex = binarySearch(data, (midIndex) => {
|
|
73
|
-
const midVal = data[midIndex][dataIndex];
|
|
74
|
-
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
75
|
-
return order === "asc" ? compareRes : -compareRes;
|
|
76
|
-
});
|
|
77
|
-
data.splice(sIndex, 0, newItem);
|
|
78
79
|
return data;
|
|
79
80
|
}
|
|
80
81
|
function binarySearch(searchArray, compareCallback) {
|
|
@@ -1094,7 +1095,7 @@ function useVirtualScroll({
|
|
|
1094
1095
|
const rowHeight = getRowHeightFn.value();
|
|
1095
1096
|
if (props.autoRowHeight) {
|
|
1096
1097
|
let offsetBottom = 0;
|
|
1097
|
-
for (let i = endIndex; i < dataSourceCopyValue.length; i++) {
|
|
1098
|
+
for (let i = endIndex + 1; i < dataSourceCopyValue.length; i++) {
|
|
1098
1099
|
const rowHeight2 = getRowHeightFn.value(dataSourceCopyValue[i]);
|
|
1099
1100
|
offsetBottom += rowHeight2;
|
|
1100
1101
|
}
|
|
@@ -1165,7 +1166,7 @@ function useVirtualScroll({
|
|
|
1165
1166
|
}
|
|
1166
1167
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
1167
1168
|
let scrollTop = ((_a = tableContainerRef.value) == null ? void 0 : _a.scrollTop) || 0;
|
|
1168
|
-
const rowHeight = getRowHeightFn.value(
|
|
1169
|
+
const rowHeight = getRowHeightFn.value();
|
|
1169
1170
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
1170
1171
|
const { headless } = props;
|
|
1171
1172
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -1219,17 +1220,18 @@ function useVirtualScroll({
|
|
|
1219
1220
|
}
|
|
1220
1221
|
function updateVirtualScrollY(sTop = 0) {
|
|
1221
1222
|
var _a;
|
|
1222
|
-
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
1223
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex, containerHeight } = virtualScroll.value;
|
|
1223
1224
|
virtualScroll.value.scrollTop = sTop;
|
|
1224
1225
|
if (!virtual_on.value) {
|
|
1225
1226
|
return;
|
|
1226
1227
|
}
|
|
1227
1228
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
1228
|
-
const rowHeight = getRowHeightFn.value(
|
|
1229
|
+
const rowHeight = getRowHeightFn.value();
|
|
1229
1230
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
1231
|
+
const dataLength = dataSourceCopyTemp.length;
|
|
1230
1232
|
let startIndex = 0;
|
|
1233
|
+
let endIndex = dataLength;
|
|
1231
1234
|
let autoRowHeightTop = 0;
|
|
1232
|
-
const dataLength = dataSourceCopyTemp.length;
|
|
1233
1235
|
if (autoRowHeight || hasExpandCol.value) {
|
|
1234
1236
|
if (autoRowHeight) {
|
|
1235
1237
|
(_a = trRef.value) == null ? void 0 : _a.forEach((tr) => {
|
|
@@ -1241,16 +1243,24 @@ function useVirtualScroll({
|
|
|
1241
1243
|
for (let i = 0; i < dataLength; i++) {
|
|
1242
1244
|
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1243
1245
|
autoRowHeightTop += height;
|
|
1244
|
-
if (autoRowHeightTop
|
|
1246
|
+
if (autoRowHeightTop >= sTop) {
|
|
1245
1247
|
startIndex = i;
|
|
1246
1248
|
autoRowHeightTop -= height;
|
|
1247
1249
|
break;
|
|
1248
1250
|
}
|
|
1249
1251
|
}
|
|
1252
|
+
let containerHeightSum = 0;
|
|
1253
|
+
for (let i = startIndex + 1; i < dataLength; i++) {
|
|
1254
|
+
containerHeightSum += getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1255
|
+
if (containerHeightSum >= containerHeight) {
|
|
1256
|
+
endIndex = i;
|
|
1257
|
+
break;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1250
1260
|
} else {
|
|
1251
1261
|
startIndex = Math.floor(sTop / rowHeight);
|
|
1262
|
+
endIndex = startIndex + pageSize;
|
|
1252
1263
|
}
|
|
1253
|
-
let endIndex = startIndex + pageSize;
|
|
1254
1264
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
1255
1265
|
startIndex -= 1;
|
|
1256
1266
|
if (autoRowHeight || hasExpandCol.value) {
|
package/package.json
CHANGED
|
@@ -112,7 +112,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
112
112
|
const rowHeight = getRowHeightFn.value();
|
|
113
113
|
if (props.autoRowHeight) {
|
|
114
114
|
let offsetBottom = 0;
|
|
115
|
-
for (let i = endIndex; i < dataSourceCopyValue.length; i++) {
|
|
115
|
+
for (let i = endIndex + 1; i < dataSourceCopyValue.length; i++) {
|
|
116
116
|
const rowHeight = getRowHeightFn.value(dataSourceCopyValue[i]);
|
|
117
117
|
offsetBottom += rowHeight;
|
|
118
118
|
}
|
|
@@ -212,7 +212,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
212
212
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
213
213
|
let scrollTop = tableContainerRef.value?.scrollTop || 0;
|
|
214
214
|
|
|
215
|
-
const rowHeight = getRowHeightFn.value(
|
|
215
|
+
const rowHeight = getRowHeightFn.value();
|
|
216
216
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
217
217
|
const { headless } = props;
|
|
218
218
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -275,7 +275,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
275
275
|
|
|
276
276
|
/** 通过滚动条位置,计算虚拟滚动的参数 */
|
|
277
277
|
function updateVirtualScrollY(sTop = 0) {
|
|
278
|
-
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
278
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex, containerHeight } = virtualScroll.value;
|
|
279
279
|
// 先更新滚动条位置记录,其他地方有依赖。(stripe 时ArrowUp/Down滚动依赖)
|
|
280
280
|
virtualScroll.value.scrollTop = sTop;
|
|
281
281
|
|
|
@@ -285,12 +285,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
288
|
-
const rowHeight = getRowHeightFn.value(
|
|
288
|
+
const rowHeight = getRowHeightFn.value();
|
|
289
289
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
290
|
+
const dataLength = dataSourceCopyTemp.length;
|
|
290
291
|
|
|
291
292
|
let startIndex = 0;
|
|
293
|
+
let endIndex = dataLength;
|
|
292
294
|
let autoRowHeightTop = 0;
|
|
293
|
-
const dataLength = dataSourceCopyTemp.length;
|
|
294
295
|
|
|
295
296
|
if (autoRowHeight || hasExpandCol.value) {
|
|
296
297
|
if (autoRowHeight) {
|
|
@@ -300,22 +301,30 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
300
301
|
autoRowHeightMap.set(rowKey, tr.offsetHeight);
|
|
301
302
|
});
|
|
302
303
|
}
|
|
303
|
-
|
|
304
|
+
// calculate startIndex
|
|
304
305
|
for (let i = 0; i < dataLength; i++) {
|
|
305
306
|
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
306
307
|
autoRowHeightTop += height;
|
|
307
|
-
if (autoRowHeightTop
|
|
308
|
+
if (autoRowHeightTop >= sTop) {
|
|
308
309
|
startIndex = i;
|
|
309
310
|
autoRowHeightTop -= height;
|
|
310
311
|
break;
|
|
311
312
|
}
|
|
312
313
|
}
|
|
314
|
+
// calculate endIndex
|
|
315
|
+
let containerHeightSum = 0;
|
|
316
|
+
for (let i = startIndex + 1; i < dataLength; i++) {
|
|
317
|
+
containerHeightSum += getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
318
|
+
if (containerHeightSum >= containerHeight) {
|
|
319
|
+
endIndex = i;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
313
323
|
} else {
|
|
314
324
|
startIndex = Math.floor(sTop / rowHeight);
|
|
325
|
+
endIndex = startIndex + pageSize;
|
|
315
326
|
}
|
|
316
327
|
|
|
317
|
-
let endIndex = startIndex + pageSize;
|
|
318
|
-
|
|
319
328
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
320
329
|
// 斑马纹情况下,每滚动偶数行才加载。防止斑马纹错位。
|
|
321
330
|
startIndex -= 1; // 奇数-1变成偶数
|
|
@@ -326,8 +335,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
326
335
|
}
|
|
327
336
|
|
|
328
337
|
startIndex = Math.max(0, startIndex);
|
|
329
|
-
|
|
330
|
-
// 溢出修正
|
|
331
338
|
endIndex = Math.min(endIndex, dataLength);
|
|
332
339
|
|
|
333
340
|
if (startIndex >= endIndex) {
|
|
@@ -34,21 +34,21 @@ export function insertToOrderedArray<T extends object>(sortState: SortState<T>,
|
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const targetVal: any = newItem[dataIndex];
|
|
38
|
+
if (sortConfig.emptyToBottom && isEmptyValue(targetVal)) {
|
|
38
39
|
// 空值排在最下方
|
|
39
40
|
data.push(newItem);
|
|
41
|
+
} else {
|
|
42
|
+
const isNumber = sortType === 'number';
|
|
43
|
+
// 二分插入
|
|
44
|
+
const sIndex = binarySearch(data, midIndex => {
|
|
45
|
+
const midVal: any = data[midIndex][dataIndex];
|
|
46
|
+
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
47
|
+
return order === 'asc' ? compareRes : -compareRes;
|
|
48
|
+
});
|
|
49
|
+
data.splice(sIndex, 0, newItem);
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
const isNumber = sortType === 'number';
|
|
43
|
-
|
|
44
|
-
// 二分插入
|
|
45
|
-
const targetVal: any = newItem[dataIndex];
|
|
46
|
-
const sIndex = binarySearch(data, midIndex => {
|
|
47
|
-
const midVal: any = data[midIndex][dataIndex];
|
|
48
|
-
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
49
|
-
return order === 'asc' ? compareRes : -compareRes;
|
|
50
|
-
});
|
|
51
|
-
data.splice(sIndex, 0, newItem);
|
|
52
52
|
return data;
|
|
53
53
|
}
|
|
54
54
|
|