Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(grid): preserve sort order when paginating (#128)

t8y2ecbd94c7bebd
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<QueryTab | undefined>)
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();
}