Skip to content

Commit dd4d5e1

Browse files
committed
fix: improve row visibility calculation in ResourceListTableVirtual component
1 parent 722c072 commit dd4d5e1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

adminforth/spa/src/components/ResourceListTableVirtual.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,15 @@ const calculateVisibleRows = () => {
658658
const buffer = props.bufferSize || 5;
659659
const containerHeight = props.containerHeight || 900;
660660
661+
// For single item or small datasets, show all rows
662+
if (props.rows.length <= buffer * 2 + 1) {
663+
startIndex.value = 0;
664+
endIndex.value = props.rows.length - 1;
665+
visibleRows.value = props.rows;
666+
spacerHeight.value = 0;
667+
return;
668+
}
669+
661670
// Binary search for start index
662671
let low = 0;
663672
let high = rowPositions.value.length - 1;
@@ -678,12 +687,17 @@ const calculateVisibleRows = () => {
678687
newStartIndex + Math.ceil(containerHeight / (props.itemHeight || 52.5)) + buffer * 2
679688
);
680689
681-
if (newStartIndex !== startIndex.value || newEndIndex !== endIndex.value) {
690+
// Ensure at least one row is visible
691+
if (newEndIndex < newStartIndex) {
692+
startIndex.value = 0;
693+
endIndex.value = Math.min(props.rows.length - 1, Math.ceil(containerHeight / (props.itemHeight || 52.5)));
694+
} else {
682695
startIndex.value = newStartIndex;
683696
endIndex.value = newEndIndex;
684-
visibleRows.value = props.rows.slice(startIndex.value, endIndex.value + 1);
685-
spacerHeight.value = startIndex.value > 0 ? rowPositions.value[startIndex.value - 1] : 0;
686697
}
698+
699+
visibleRows.value = props.rows.slice(startIndex.value, endIndex.value + 1);
700+
spacerHeight.value = startIndex.value > 0 ? rowPositions.value[startIndex.value - 1] : 0;
687701
};
688702
689703
// Throttled scroll handler

0 commit comments

Comments
 (0)