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({