fix(grid): reset infinite scroll state on database sort

Closes #5172
This commit is contained in:
t8y2 2026-08-03 16:37:42 +08:00
parent 212cf1da7e
commit 246dfad018
No known key found for this signature in database
2 changed files with 41 additions and 2 deletions

View File

@ -4379,8 +4379,12 @@ function setDetailNull() {
function applyColumnSort(column: string, columnIndex: number, direction: "asc" | "desc" | null, mode: DataGridSortMode = "database") {
if (getIsResizing()) return;
currentPage.value = 1;
resetGridVerticalScroll(true);
if (mode === "database" && infiniteScrollEnabled.value) {
resetInfiniteScrollState();
} else {
currentPage.value = 1;
resetGridVerticalScroll(true);
}
if (direction) {
setSort(column, columnIndex, direction, mode);
if (mode === "database") {

View File

@ -0,0 +1,35 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
function functionSource(name: string, nextName: string): string {
const start = dataGridSource.indexOf(`function ${name}`);
const relativeEnd = dataGridSource.slice(start).search(new RegExp(`\\n(?:async\\s+)?function\\s+${nextName}\\b`));
expect(start).toBeGreaterThanOrEqual(0);
expect(relativeEnd).toBeGreaterThan(0);
const end = start + relativeEnd;
return dataGridSource.slice(start, end);
}
describe("DataGrid infinite-scroll sorting", () => {
it("clears completed and pending infinite-scroll state before database sorting", () => {
const sortSource = functionSource("applyColumnSort", "selectHeaderSort");
const resetSource = functionSource("resetInfiniteScrollState", "onToolbarRefresh");
expect(sortSource).toContain('if (mode === "database" && infiniteScrollEnabled.value) {\n resetInfiniteScrollState();');
expect(resetSource).toContain("lastInfiniteScrollPage = 0;");
expect(resetSource).toContain("infiniteScrollAllLoaded = false;");
expect(resetSource).toContain("infiniteScrollRequestedOffset = undefined;");
expect(resetSource).toContain("infiniteScrollRequestedLimit = undefined;");
expect(resetSource).toContain("isInfiniteScrollPaginating.value = false;");
expect(resetSource).toContain("infiniteScrollLoading.value = false;");
});
it("preserves the existing lightweight reset for local sorting", () => {
const sortSource = functionSource("applyColumnSort", "selectHeaderSort");
expect(sortSource).toContain("} else {\n currentPage.value = 1;\n resetGridVerticalScroll(true);\n }");
expect(sortSource.match(/emit\("sort"/g)).toHaveLength(1);
});
});