From ecbd94c7bebd4b891386fd712a7666f7055e7eff Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 7 May 2026 10:44:11 +0800 Subject: [PATCH] fix(grid): preserve sort order when paginating (#128) --- src/components/grid/DataGrid.vue | 12 ++++++++---- src/components/layout/ContentArea.vue | 5 +++-- src/composables/useDataGridActions.ts | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue index 80814f4471..903af8738a 100644 --- a/src/components/grid/DataGrid.vue +++ b/src/components/grid/DataGrid.vue @@ -94,7 +94,7 @@ const props = defineProps<{ const emit = defineEmits<{ reload: []; - paginate: [offset: number, limit: number, whereInput?: string]; + paginate: [offset: number, limit: number, whereInput?: string, orderBy?: string]; sort: [column: string, direction: "asc" | "desc" | null, whereInput?: string]; }>(); @@ -426,20 +426,24 @@ const wherePredicate = computed(() => normalizeWhereInput(searchText.value)); const activeWhereInput = computed(() => (isWhereSearch.value && wherePredicate.value ? searchText.value : undefined)); const clientSearchText = computed(() => (isWhereSearch.value ? "" : searchText.value)); +function currentOrderBy(): string | undefined { + return sortCol.value ? `${quoteIdent(sortCol.value)} ${sortDir.value.toUpperCase()}` : undefined; +} + function prevPage() { if (currentPage.value <= 1) return; currentPage.value--; - emit("paginate", (currentPage.value - 1) * pageSize.value, pageSize.value, activeWhereInput.value); + emit("paginate", (currentPage.value - 1) * pageSize.value, pageSize.value, activeWhereInput.value, currentOrderBy()); } function nextPage() { if (!isFullPage.value) return; currentPage.value++; - emit("paginate", (currentPage.value - 1) * pageSize.value, pageSize.value, activeWhereInput.value); + emit("paginate", (currentPage.value - 1) * pageSize.value, pageSize.value, activeWhereInput.value, currentOrderBy()); } function changePageSize(size: number) { pageSize.value = size; currentPage.value = 1; - emit("paginate", 0, size, activeWhereInput.value); + emit("paginate", 0, size, activeWhereInput.value, currentOrderBy()); } // --- Editing --- diff --git a/src/components/layout/ContentArea.vue b/src/components/layout/ContentArea.vue index dd3b6f6041..0abe6579ce 100644 --- a/src/components/layout/ContentArea.vue +++ b/src/components/layout/ContentArea.vue @@ -40,7 +40,7 @@ const emit = defineEmits<{ editorCursorChange: [pos: number]; formatError: []; reload: []; - paginate: [offset: number, limit: number, whereInput?: string]; + paginate: [offset: number, limit: number, whereInput?: string, orderBy?: string]; sort: [column: string, direction: "asc" | "desc" | null, whereInput?: string]; executeSql: [sql: string]; clickTable: [tableName: string]; @@ -341,7 +341,8 @@ function onHandleCloseColumnPanel() { :on-execute-sql="async (sql: string) => emit('executeSql', sql)" @reload="emit('reload')" @paginate=" - (offset: number, limit: number, whereInput?: string) => emit('paginate', offset, limit, whereInput) + (offset: number, limit: number, whereInput?: string, orderBy?: string) => + emit('paginate', offset, limit, whereInput, orderBy) " @sort=" (column: string, direction: 'asc' | 'desc' | null, whereInput?: string) => diff --git a/src/composables/useDataGridActions.ts b/src/composables/useDataGridActions.ts index 4c5dde34b6..1feea2e1b2 100644 --- a/src/composables/useDataGridActions.ts +++ b/src/composables/useDataGridActions.ts @@ -48,10 +48,10 @@ export function useDataGridActions(activeTab: ComputedRef) queryStore.executeCurrentTab(); } - async function onPaginate(offset: number, limit: number, whereInput?: string) { + async function onPaginate(offset: number, limit: number, whereInput?: string, orderBy?: string) { const tab = activeTab.value; if (!tab?.tableMeta) return; - const sql = buildTableSql(tab, { limit, offset, whereInput }); + const sql = buildTableSql(tab, { limit, offset, whereInput, orderBy }); queryStore.updateSql(tab.id, sql); await queryStore.executeCurrentTab(); }