stk-table-vue 0.6.15 → 0.6.16
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 +16 -7
- package/package.json +1 -1
- package/src/StkTable/useVirtualScroll.ts +18 -11
package/lib/stk-table-vue.js
CHANGED
|
@@ -1094,7 +1094,7 @@ function useVirtualScroll({
|
|
|
1094
1094
|
const rowHeight = getRowHeightFn.value();
|
|
1095
1095
|
if (props.autoRowHeight) {
|
|
1096
1096
|
let offsetBottom = 0;
|
|
1097
|
-
for (let i = endIndex; i < dataSourceCopyValue.length; i++) {
|
|
1097
|
+
for (let i = endIndex + 1; i < dataSourceCopyValue.length; i++) {
|
|
1098
1098
|
const rowHeight2 = getRowHeightFn.value(dataSourceCopyValue[i]);
|
|
1099
1099
|
offsetBottom += rowHeight2;
|
|
1100
1100
|
}
|
|
@@ -1165,7 +1165,7 @@ function useVirtualScroll({
|
|
|
1165
1165
|
}
|
|
1166
1166
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
1167
1167
|
let scrollTop = ((_a = tableContainerRef.value) == null ? void 0 : _a.scrollTop) || 0;
|
|
1168
|
-
const rowHeight = getRowHeightFn.value(
|
|
1168
|
+
const rowHeight = getRowHeightFn.value();
|
|
1169
1169
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
1170
1170
|
const { headless } = props;
|
|
1171
1171
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -1219,17 +1219,18 @@ function useVirtualScroll({
|
|
|
1219
1219
|
}
|
|
1220
1220
|
function updateVirtualScrollY(sTop = 0) {
|
|
1221
1221
|
var _a;
|
|
1222
|
-
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
1222
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex, containerHeight } = virtualScroll.value;
|
|
1223
1223
|
virtualScroll.value.scrollTop = sTop;
|
|
1224
1224
|
if (!virtual_on.value) {
|
|
1225
1225
|
return;
|
|
1226
1226
|
}
|
|
1227
1227
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
1228
|
-
const rowHeight = getRowHeightFn.value(
|
|
1228
|
+
const rowHeight = getRowHeightFn.value();
|
|
1229
1229
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
1230
|
+
const dataLength = dataSourceCopyTemp.length;
|
|
1230
1231
|
let startIndex = 0;
|
|
1232
|
+
let endIndex = dataLength;
|
|
1231
1233
|
let autoRowHeightTop = 0;
|
|
1232
|
-
const dataLength = dataSourceCopyTemp.length;
|
|
1233
1234
|
if (autoRowHeight || hasExpandCol.value) {
|
|
1234
1235
|
if (autoRowHeight) {
|
|
1235
1236
|
(_a = trRef.value) == null ? void 0 : _a.forEach((tr) => {
|
|
@@ -1241,16 +1242,24 @@ function useVirtualScroll({
|
|
|
1241
1242
|
for (let i = 0; i < dataLength; i++) {
|
|
1242
1243
|
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1243
1244
|
autoRowHeightTop += height;
|
|
1244
|
-
if (autoRowHeightTop
|
|
1245
|
+
if (autoRowHeightTop >= sTop) {
|
|
1245
1246
|
startIndex = i;
|
|
1246
1247
|
autoRowHeightTop -= height;
|
|
1247
1248
|
break;
|
|
1248
1249
|
}
|
|
1249
1250
|
}
|
|
1251
|
+
let containerHeightSum = 0;
|
|
1252
|
+
for (let i = startIndex + 1; i < dataLength; i++) {
|
|
1253
|
+
containerHeightSum += getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1254
|
+
if (containerHeightSum >= containerHeight) {
|
|
1255
|
+
endIndex = i;
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1250
1259
|
} else {
|
|
1251
1260
|
startIndex = Math.floor(sTop / rowHeight);
|
|
1261
|
+
endIndex = startIndex + pageSize;
|
|
1252
1262
|
}
|
|
1253
|
-
let endIndex = startIndex + pageSize;
|
|
1254
1263
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
1255
1264
|
startIndex -= 1;
|
|
1256
1265
|
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) {
|