stk-table-vue 0.6.14 → 0.6.15

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.
@@ -1089,9 +1089,18 @@ function useVirtualScroll({
1089
1089
  });
1090
1090
  const virtual_offsetBottom = computed(() => {
1091
1091
  if (!virtual_on.value) return 0;
1092
- const { startIndex } = virtualScroll.value;
1092
+ const { startIndex, endIndex } = virtualScroll.value;
1093
+ const dataSourceCopyValue = dataSourceCopy.value;
1093
1094
  const rowHeight = getRowHeightFn.value();
1094
- return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
1095
+ if (props.autoRowHeight) {
1096
+ let offsetBottom = 0;
1097
+ for (let i = endIndex; i < dataSourceCopyValue.length; i++) {
1098
+ const rowHeight2 = getRowHeightFn.value(dataSourceCopyValue[i]);
1099
+ offsetBottom += rowHeight2;
1100
+ }
1101
+ return offsetBottom;
1102
+ }
1103
+ return (dataSourceCopyValue.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
1095
1104
  });
1096
1105
  const virtualX_on = computed(() => {
1097
1106
  return props.virtualX && tableHeaderLast.value.reduce((sum, col) => sum += getCalculatedColWidth(col), 0) > virtualScrollX.value.containerWidth + 100;
@@ -1183,9 +1192,9 @@ function useVirtualScroll({
1183
1192
  const autoRowHeightMap = /* @__PURE__ */ new Map();
1184
1193
  function setAutoHeight(rowKey, height) {
1185
1194
  if (!height) {
1186
- autoRowHeightMap.delete(rowKey);
1195
+ autoRowHeightMap.delete(String(rowKey));
1187
1196
  } else {
1188
- autoRowHeightMap.set(rowKey, height);
1197
+ autoRowHeightMap.set(String(rowKey), height);
1189
1198
  }
1190
1199
  }
1191
1200
  function clearAllAutoHeight() {
@@ -1195,7 +1204,7 @@ function useVirtualScroll({
1195
1204
  var _a;
1196
1205
  if (!row) return;
1197
1206
  const rowKey = rowKeyGen(row);
1198
- const storedHeight = autoRowHeightMap.get(rowKey);
1207
+ const storedHeight = autoRowHeightMap.get(String(rowKey));
1199
1208
  if (storedHeight) {
1200
1209
  return storedHeight;
1201
1210
  }
@@ -1232,7 +1241,7 @@ function useVirtualScroll({
1232
1241
  for (let i = 0; i < dataLength; i++) {
1233
1242
  const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
1234
1243
  autoRowHeightTop += height;
1235
- if (autoRowHeightTop >= sTop) {
1244
+ if (autoRowHeightTop > sTop) {
1236
1245
  startIndex = i;
1237
1246
  autoRowHeightTop -= height;
1238
1247
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.6.14",
3
+ "version": "0.6.15",
4
4
  "description": "Simple 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",
@@ -107,9 +107,19 @@ export function useVirtualScroll<DT extends Record<string, any>>({
107
107
 
108
108
  const virtual_offsetBottom = computed(() => {
109
109
  if (!virtual_on.value) return 0;
110
- const { startIndex } = virtualScroll.value;
110
+ const { startIndex, endIndex } = virtualScroll.value;
111
+ const dataSourceCopyValue = dataSourceCopy.value;
111
112
  const rowHeight = getRowHeightFn.value();
112
- return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
113
+ if (props.autoRowHeight) {
114
+ let offsetBottom = 0;
115
+ for (let i = endIndex; i < dataSourceCopyValue.length; i++) {
116
+ const rowHeight = getRowHeightFn.value(dataSourceCopyValue[i]);
117
+ offsetBottom += rowHeight;
118
+ }
119
+ return offsetBottom;
120
+ }
121
+
122
+ return (dataSourceCopyValue.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
113
123
  });
114
124
 
115
125
  const virtualX_on = computed(() => {
@@ -232,13 +242,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
232
242
  let vue2ScrollYTimeout: null | number = null;
233
243
 
234
244
  /** every row actual height */
235
- const autoRowHeightMap = new Map<UniqKey, number>();
245
+ const autoRowHeightMap = new Map<string, number>();
236
246
  /** 如果行高度有变化,则要调用此方法清除保存的行高 */
237
247
  function setAutoHeight(rowKey: UniqKey, height?: number | null) {
238
248
  if (!height) {
239
- autoRowHeightMap.delete(rowKey);
249
+ autoRowHeightMap.delete(String(rowKey));
240
250
  } else {
241
- autoRowHeightMap.set(rowKey, height);
251
+ autoRowHeightMap.set(String(rowKey), height);
242
252
  }
243
253
  }
244
254
 
@@ -249,7 +259,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
249
259
  function getAutoRowHeight(row?: DT) {
250
260
  if (!row) return;
251
261
  const rowKey = rowKeyGen(row);
252
- const storedHeight = autoRowHeightMap.get(rowKey);
262
+ const storedHeight = autoRowHeightMap.get(String(rowKey));
253
263
  if (storedHeight) {
254
264
  return storedHeight;
255
265
  }
@@ -294,7 +304,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
294
304
  for (let i = 0; i < dataLength; i++) {
295
305
  const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
296
306
  autoRowHeightTop += height;
297
- if (autoRowHeightTop >= sTop) {
307
+ if (autoRowHeightTop > sTop) {
298
308
  startIndex = i;
299
309
  autoRowHeightTop -= height;
300
310
  break;