From 70b55fe49ab948e4f2442db6ec9620e399636854 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sat, 9 May 2026 00:11:46 +0800 Subject: [PATCH] feat: add independent WHERE and ORDER BY filter inputs to data grid (#165) - Split WHERE and ORDER BY into separate inputs alongside search bar - Three equal sections: Search | WHERE | ORDER BY with border separators - Preserve tableMeta on error so filters remain visible after failed queries - Show schema@database format in table data badge --- src/components/grid/DataGrid.vue | 210 +++++++++++++++++++------- src/components/layout/ContentArea.vue | 4 +- src/stores/queryStore.ts | 2 +- 3 files changed, 158 insertions(+), 58 deletions(-) diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue index 0f2855b5b6..77daed87c0 100644 --- a/src/components/grid/DataGrid.vue +++ b/src/components/grid/DataGrid.vue @@ -432,6 +432,11 @@ const wherePredicate = computed(() => (canUseWhereSearch.value ? normalizeWhereI const activeWhereInput = computed(() => (isWhereSearch.value && wherePredicate.value ? searchText.value : undefined)); const clientSearchText = computed(() => (isWhereSearch.value ? "" : searchText.value)); +const orderByInput = ref(""); +const hasOrderByInput = computed(() => orderByInput.value.trim().length > 0); +const whereFilterInput = ref(""); +const hasWhereFilterInput = computed(() => whereFilterInput.value.trim().length > 0); + function currentOrderBy(): string | undefined { return sortCol.value ? `${quoteIdent(sortCol.value)} ${sortDir.value.toUpperCase()}` : undefined; } @@ -651,6 +656,58 @@ async function applyWhereSearch() { } } +async function applyOrderBySearch() { + if (!props.tableMeta || !props.onExecuteSql) return; + const orderByClause = orderByInput.value.trim() || undefined; + isApplyingWhere.value = true; + saveError.value = ""; + currentPage.value = 1; + sortCol.value = null; + sortColIndex.value = null; + sortDir.value = "asc"; + try { + const sql = buildTableSelectSql({ + databaseType: props.databaseType, + schema: props.tableMeta.schema, + tableName: props.tableMeta.tableName, + primaryKeys: props.tableMeta.primaryKeys, + orderBy: orderByClause, + limit: pageSize.value, + whereInput: whereFilterInput.value.trim() || undefined, + }); + await props.onExecuteSql(sql); + } catch (e: any) { + saveError.value = String(e?.message || e); + } finally { + isApplyingWhere.value = false; + } +} + +async function applyWhereFilter() { + if (!props.tableMeta || !props.onExecuteSql) return; + isApplyingWhere.value = true; + saveError.value = ""; + currentPage.value = 1; + try { + const sql = buildTableSelectSql({ + databaseType: props.databaseType, + schema: props.tableMeta.schema, + tableName: props.tableMeta.tableName, + primaryKeys: props.tableMeta.primaryKeys, + orderBy: + orderByInput.value.trim() || + (sortCol.value ? `${quoteIdent(sortCol.value)} ${sortDir.value.toUpperCase()}` : undefined), + limit: pageSize.value, + whereInput: whereFilterInput.value.trim() || undefined, + }); + await props.onExecuteSql(sql); + } catch (e: any) { + saveError.value = String(e?.message || e); + } finally { + isApplyingWhere.value = false; + } +} + const CELL_DISPLAY_MAX_LENGTH = 256; function formatCell(value: CellValue): string { @@ -1297,71 +1354,114 @@ defineExpose({