fix(grid): stop infinite scroll at exact total
This commit is contained in:
4 files changed
+52
-2
No files matched your search
@@ -134,7 +134,7 @@ import { applyColumnFormatter, buildColumnFormatterKey, getSupportedTimeZoneOpti
|
||||
import { temporalCellEditorConfig, type TemporalCellEditorConfig } from "@/lib/dataGrid/dataGridTemporalEditor";
|
||||
import { isCancelSearchShortcut, isCopyCurrentRowShortcut, isDeleteCurrentRowShortcut, isFocusSearchShortcut, isModRShortcut, isSaveShortcut, isToggleTransposeShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGrid/dataGridScrollGutter";
|
||||
import { canGoNextDataGridPage, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal } from "@/lib/dataGrid/dataGridPagination";
|
||||
import { canFetchNextDataGridSegment, canGoNextDataGridPage, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal } from "@/lib/dataGrid/dataGridPagination";
|
||||
import { dataGridCountQueryOptions } from "@/lib/dataGrid/dataGridQueryOptions";
|
||||
import { dataGridBottomScrollTop, dataGridScrollPosition, isDataGridAtScrollBottom, isDataGridNearScrollBottom, shouldCheckInfiniteScrollAfterScroll, type DataGridScrollPosition } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
import { CANVAS_DATA_GRID_ROW_HEIGHT, canvasDataGridActionReservedWidth, dataGridSearchMatchKey, drawCanvasDataGrid } from "@/lib/dataGrid/canvasDataGridRenderer";
|
||||
@@ -2469,6 +2469,15 @@ const canGoNextPage = computed(() => {
|
||||
allRowsLoaded: allRowsLoaded.value,
|
||||
});
|
||||
});
|
||||
const canFetchNextInfiniteScrollSegment = computed(() =>
|
||||
canFetchNextDataGridSegment({
|
||||
hasMore: props.result.has_more,
|
||||
loadedRowCount: props.result.rows.length,
|
||||
pageSize: pageSize.value,
|
||||
totalRowCount: hasKnownPaginationTotalRowCount.value ? paginationTotalRowCount.value : undefined,
|
||||
allRowsLoaded: allRowsLoaded.value,
|
||||
}),
|
||||
);
|
||||
const canJumpLastPage = computed(() => canGoNextPage.value && (hasKnownPaginationTotalRowCount.value || allRowsLoaded.value || !!props.tableMeta || !!props.countSql));
|
||||
const totalRowCountBusy = computed(() => props.totalRowCountLoading === true || manualTotalRowCountLoading.value);
|
||||
const canCalculateTotalRowCount = computed(() => !!props.connectionId && (!!props.tableMeta || !!props.countSql));
|
||||
@@ -2596,6 +2605,10 @@ function nextPage() {
|
||||
|
||||
function infiniteScrollNextPage() {
|
||||
if (infiniteScrollLoading.value || props.loading) return;
|
||||
if (!canFetchNextInfiniteScrollSegment.value) {
|
||||
infiniteScrollAllLoaded = true;
|
||||
return;
|
||||
}
|
||||
const nextOffset = props.result.rows.length;
|
||||
const remainingRows = infiniteScrollMaxRows.value - nextOffset;
|
||||
if (remainingRows <= 0) return;
|
||||
|
||||
@@ -21,6 +21,14 @@ export interface CompleteLocalDataGridResultOptions {
|
||||
hasMore?: boolean;
|
||||
}
|
||||
|
||||
export interface CanFetchNextDataGridSegmentOptions {
|
||||
hasMore?: boolean;
|
||||
loadedRowCount: number;
|
||||
pageSize: number;
|
||||
totalRowCount?: number;
|
||||
allRowsLoaded?: boolean;
|
||||
}
|
||||
|
||||
export function resolveDataGridPaginationTotal(options: { paginationTotalRowCount?: number; serverKnownTotalRowCount?: number; totalRowCountIsExact: boolean }): number | undefined {
|
||||
if (options.paginationTotalRowCount !== undefined) return options.paginationTotalRowCount;
|
||||
return options.totalRowCountIsExact ? options.serverKnownTotalRowCount : undefined;
|
||||
@@ -55,3 +63,15 @@ export function canGoNextDataGridPage(options: CanGoNextDataGridPageOptions): bo
|
||||
|
||||
return options.rowCount >= pageSize;
|
||||
}
|
||||
|
||||
export function canFetchNextDataGridSegment(options: CanFetchNextDataGridSegmentOptions): boolean {
|
||||
if (options.hasMore === true) return true;
|
||||
|
||||
const totalRowCount = options.totalRowCount;
|
||||
if (typeof totalRowCount === "number" && Number.isFinite(totalRowCount) && totalRowCount >= 0) {
|
||||
return options.loadedRowCount < totalRowCount;
|
||||
}
|
||||
|
||||
if (options.allRowsLoaded === true) return false;
|
||||
return options.loadedRowCount >= Math.max(1, options.pageSize);
|
||||
}
|
||||
Reference in new issue
Block a user