stk-table-vue 0.8.6 → 0.8.7

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/style.css CHANGED
@@ -184,8 +184,10 @@
184
184
  }
185
185
  .stk-table .row-by-row-table-height{
186
186
  width:1px;
187
+ flex-shrink:0;
187
188
  position:absolute;
188
189
  left:0;
190
+ top:0;
189
191
  }
190
192
  .stk-table th,
191
193
  .stk-table td{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
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",
@@ -36,12 +36,7 @@
36
36
  @scroll="onTableScroll"
37
37
  @wheel="onTableWheel"
38
38
  >
39
-
40
- <div
41
- v-if="isSRBRActive && virtual"
42
- class="row-by-row-table-height"
43
- :style="{ height: dataSourceCopy.length * virtualScroll.rowHeight + 'px' }"
44
- ></div>
39
+ <div v-if="SRBRTotalHeight" class="row-by-row-table-height" :style="`height: ${SRBRTotalHeight}px`"></div>
45
40
 
46
41
  <div v-if="colResizable" ref="colResizeIndicatorRef" class="column-resize-indicator"></div>
47
42
  <table
@@ -240,6 +235,7 @@
240
235
  </template>
241
236
  </tr>
242
237
  <tr v-if="virtual_on && !isSRBRActive" :style="`height: ${virtual_offsetBottom}px`"></tr>
238
+ <tr v-if="SRBRBottomHeight" :style="`height: ${SRBRBottomHeight}px`"></tr>
243
239
  </tbody>
244
240
  </table>
245
241
  <div v-if="(!dataSourceCopy || !dataSourceCopy.length) && showNoData" class="stk-table-no-data" :class="{ 'no-data-full': noDataFull }">
@@ -744,6 +740,18 @@ const getEmptyCellText = computed(() => {
744
740
  }
745
741
  });
746
742
 
743
+ /** scroll-row-by-row total-height */
744
+ const SRBRTotalHeight = computed(() => {
745
+ if (!isSRBRActive.value || !props.virtual) return 0;
746
+ return (
747
+ dataSourceCopy.value.length * virtualScroll.value.rowHeight + tableHeaderHeight.value //+
748
+ );
749
+ });
750
+ const SRBRBottomHeight = computed(() => {
751
+ if (!isSRBRActive.value || !props.virtual) return 0;
752
+ return (virtualScroll.value.containerHeight - tableHeaderHeight.value) % virtualScroll.value.rowHeight;
753
+ });
754
+
747
755
  const rowKeyGenCache = new WeakMap();
748
756
 
749
757
  const { isSRBRActive } = useScrollRowByRow({ props, tableContainerRef });
@@ -763,6 +771,7 @@ const {
763
771
  virtualX_on,
764
772
  virtualX_columnPart,
765
773
  virtualX_offsetRight,
774
+ tableHeaderHeight,
766
775
  initVirtualScroll,
767
776
  initVirtualScrollY,
768
777
  initVirtualScrollX,
@@ -880,7 +889,7 @@ watch(
880
889
  console.warn('invalid dataSource');
881
890
  return;
882
891
  }
883
-
892
+
884
893
  let needInitVirtualScrollY = false;
885
894
  if (dataSourceCopy.value.length !== val.length) {
886
895
  needInitVirtualScrollY = true;
@@ -1346,7 +1355,7 @@ function onTableScroll(e: Event) {
1346
1355
  }
1347
1356
 
1348
1357
  if (isYScroll) {
1349
- const { startIndex, endIndex } = virtualScroll.value;
1358
+ const { startIndex, endIndex } = virtualScroll.value;
1350
1359
  emits('scroll', e, { startIndex, endIndex });
1351
1360
  }
1352
1361
  if (isXScroll) {
@@ -275,8 +275,10 @@
275
275
 
276
276
  .row-by-row-table-height {
277
277
  width: 1px;
278
+ flex-shrink: 0;
278
279
  position: absolute;
279
280
  left: 0;
281
+ top: 0;
280
282
  }
281
283
 
282
284
  th,
@@ -67,7 +67,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
67
67
  rowKeyGen,
68
68
  maxRowSpan,
69
69
  }: Option<DT>) {
70
- const tableHeaderHeight = ref(props.headerRowHeight);
70
+ const tableHeaderHeight = computed(() => props.headerRowHeight * tableHeaders.value.length);
71
+
71
72
 
72
73
  const virtualScroll = ref<VirtualScrollStore>({
73
74
  containerHeight: 0,
@@ -188,10 +189,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
188
189
  return rowHeightFn;
189
190
  });
190
191
 
191
- function getTableHeaderHeight() {
192
- return props.headerRowHeight * tableHeaders.value.length;
193
- }
194
-
195
192
  /**
196
193
  * 初始化虚拟滚动参数
197
194
  * @param {number} [height] 虚拟滚动的高度
@@ -210,18 +207,16 @@ export function useVirtualScroll<DT extends Record<string, any>>({
210
207
  console.warn('initVirtualScrollY: height must be a number');
211
208
  height = 0;
212
209
  }
213
- const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
210
+ const { clientHeight, scrollHeight } = tableContainerRef.value || {};
214
211
  let scrollTop = tableContainerRef.value?.scrollTop || 0;
215
212
 
216
213
  const rowHeight = getRowHeightFn.value();
217
- const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
214
+ const containerHeight = height || clientHeight || DEFAULT_TABLE_HEIGHT;
218
215
  const { headless } = props;
219
216
  let pageSize = Math.ceil(containerHeight / rowHeight);
220
- const headerHeight = getTableHeaderHeight();
221
- tableHeaderHeight.value = headerHeight;
222
217
  if (!headless) {
223
218
  /** 表头高度占几行表体高度数 */
224
- const headerToBodyRowHeightCount = Math.floor(headerHeight / rowHeight);
219
+ const headerToBodyRowHeightCount = Math.floor(tableHeaderHeight.value / rowHeight);
225
220
  pageSize -= headerToBodyRowHeightCount; //减去表头行数
226
221
  }
227
222
  const maxScrollTop = dataSourceCopy.value.length * rowHeight + tableHeaderHeight.value - containerHeight;
@@ -487,6 +482,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
487
482
  virtualX_on,
488
483
  virtualX_columnPart,
489
484
  virtualX_offsetRight,
485
+ tableHeaderHeight,
490
486
  initVirtualScroll,
491
487
  initVirtualScrollY,
492
488
  initVirtualScrollX,