fix: preserve data grid order by input

This commit is contained in:
t8y2 committed 2026-06-02 11:36:59 +08:00
1 parent 1331d36a11
commit f5eb3ba5db
6 files changed
+29 -4

No files matched your search

+16 -4
View File
@@ -200,6 +200,7 @@ const props = defineProps<{
sourceColumns?: Array<string | undefined>;
queryEditabilityReason?: string;
initialWhereInput?: string;
initialOrderByInput?: string;
sortColumn?: string;
sortColumnIndex?: number;
sortDirection?: DataGridSortDirection;
@@ -235,6 +236,7 @@ const emit = defineEmits<{
paginate: [offset: number, limit: number, whereInput?: string, orderBy?: string];
sort: [column: string, columnIndex: number, direction: "asc" | "desc" | null, whereInput?: string];
"update:whereInput": [value: string];
"update:orderByInput": [value: string];
}>();
console.info("[DBX][DataGrid:setup]", {
@@ -431,7 +433,7 @@ const orderByMeasureRef = ref<HTMLSpanElement>();
const orderBySuggestionLeft = ref(0);
const orderBySuggestionPosition = ref({ left: 0, top: 0 });
const orderByInput = ref("");
const orderByInput = ref(props.initialOrderByInput ?? "");
const hasOrderByInput = computed(() => orderByInput.value.trim().length > 0);
const whereFilterInput = ref(props.initialWhereInput ?? "");
const hasWhereFilterInput = computed(() => whereFilterInput.value.trim().length > 0);
@@ -1361,6 +1363,7 @@ function navigateOrderBySuggestion(delta: number) {
}
watch(orderByInput, (val) => {
emit("update:orderByInput", val);
orderBySuggestions.value = [];
if (!props.tableMeta?.columns?.length) return;
const trimmed = val.trim();
@@ -1756,16 +1759,24 @@ function currentOrderBy(): string | undefined {
}
function syncOrderByInputWithSort(column: string | null, direction: "asc" | "desc" | null) {
orderByInput.value = column && direction ? `${queryColumnRef(column)} ${direction.toUpperCase()}` : "";
const nextOrderByInput = column && direction ? `${queryColumnRef(column)} ${direction.toUpperCase()}` : "";
orderByInput.value = nextOrderByInput;
emit("update:orderByInput", nextOrderByInput);
}
watch(
() => [props.sortColumn, props.sortColumnIndex, props.sortDirection] as const,
([column, columnIndex, direction]) => {
([column, columnIndex, direction], previous) => {
const wasControlledSort = !!previous?.[0] && !!previous?.[2];
const isControlledSort = !!column && !!direction;
sortCol.value = column && direction ? column : null;
sortColIndex.value = typeof columnIndex === "number" && direction ? columnIndex : null;
sortDir.value = direction ?? "asc";
syncOrderByInputWithSort(sortCol.value, sortCol.value ? sortDir.value : null);
if (isControlledSort) {
syncOrderByInputWithSort(sortCol.value, sortDir.value);
} else if (wasControlledSort) {
syncOrderByInputWithSort(null, null);
}
},
{ immediate: true },
);
@@ -2752,6 +2763,7 @@ async function clearContextFilter() {
async function applyOrderBySearch() {
if (!props.tableMeta || !props.onExecuteSql) return;
const orderByClause = orderByInput.value.trim() || undefined;
emit("update:orderByInput", orderByInput.value);
isApplyingWhere.value = true;
saveError.value = "";
currentPage.value = 1;
@@ -463,6 +463,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
:sort-column="activeTab.resultSortColumn"
:sort-column-index="activeTab.resultSortColumnIndex"
:sort-direction="activeTab.resultSortDirection"
:initial-order-by-input="activeTab.orderByInput"
:sql="activeTab.lastExecutedSql || activeTab.sql"
:loading="activeTab.isExecuting"
:editable="!!activeTab.queryAnalysis"
@@ -480,6 +481,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
:total-row-count="activeTab.resultTotalRowCount"
:on-execute-sql="async (sql: string) => emit('executeSql', sql)"
:full-export-result="() => queryStore.fetchTabResultForExport(activeTab.id)"
@update:order-by-input="(v: string) => (activeTab.orderByInput = v)"
@reload="
(
sql?: string,
@@ -670,6 +672,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
:sort-column="activeTab.resultSortColumn"
:sort-column-index="activeTab.resultSortColumnIndex"
:sort-direction="activeTab.resultSortDirection"
:initial-order-by-input="activeTab.orderByInput"
:sql="activeTab.sql"
:loading="activeTab.isExecuting"
:editable="isTableDataEditable(activeConnection?.db_type, activeTab.tableMeta?.primaryKeys ?? [])"
@@ -684,6 +687,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
:on-execute-sql="async (sql: string) => emit('executeSql', sql)"
:full-export-result="() => queryStore.fetchTabResultForExport(activeTab.id)"
@update:where-input="(v: string) => (activeTab.whereInput = v)"
@update:order-by-input="(v: string) => (activeTab.orderByInput = v)"
@reload="
(
sql?: string,