diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue index a57c97d060..7b196c060c 100644 --- a/src/components/grid/DataGrid.vue +++ b/src/components/grid/DataGrid.vue @@ -64,6 +64,19 @@ function shortTypeName(t: string): string { if (s === "real") return "float4"; return t; } + +function typeColorClass(t: string): string { + const s = t.toLowerCase(); + if (["int", "int2", "int4", "int8", "smallint", "bigint", "integer", "serial", "bigserial", "tinyint", "mediumint"].includes(s)) return "text-blue-500"; + if (["float4", "float8", "double", "decimal", "numeric", "real", "float", "money"].includes(s)) return "text-cyan-500"; + if (["varchar", "text", "char", "character varying", "character", "string", "nvarchar", "nchar", "ntext", "longtext", "mediumtext", "tinytext", "clob"].includes(s)) return "text-green-500"; + if (["bool", "boolean", "bit"].includes(s)) return "text-orange-500"; + if (["timestamp", "timestamptz", "datetime", "date", "time", "timetz", "datetime2", "smalldatetime"].includes(s)) return "text-purple-500"; + if (["json", "jsonb", "xml", "array"].includes(s)) return "text-pink-500"; + if (["uuid", "uniqueidentifier"].includes(s)) return "text-amber-500"; + if (["bytea", "blob", "binary", "varbinary", "image"].includes(s)) return "text-red-400"; + return "text-muted-foreground"; +} const contextCell = ref<{ row: number; col: number } | null>(null); const sortCol = ref(null); const sortDir = ref<"asc" | "desc">("asc"); @@ -104,18 +117,19 @@ function onResizeStart(colIdx: number, event: MouseEvent) { document.addEventListener("mouseup", onUp); } +const ROW_NUM_WIDTH = 48; const baseTotalWidth = computed(() => columnWidths.value.reduce((a, b) => a + b, 0)); const renderedColumnWidths = computed(() => { const widths = columnWidths.value; if (widths.length === 0) return widths; - const extraWidth = Math.max(0, gridWidth.value - baseTotalWidth.value); + const extraWidth = Math.max(0, gridWidth.value - ROW_NUM_WIDTH - baseTotalWidth.value); if (extraWidth === 0) return widths; const extraPerColumn = extraWidth / widths.length; return widths.map((width) => width + extraPerColumn); }); -const totalWidth = computed(() => renderedColumnWidths.value.reduce((a, b) => a + b, 0)); +const totalWidth = computed(() => renderedColumnWidths.value.reduce((a, b) => a + b, 0) + ROW_NUM_WIDTH); const columnVars = computed(() => { const vars: Record = {}; @@ -486,6 +500,7 @@ const sqlOneLiner = computed(() => props.sql?.replace(/\s+/g, " ").trim() || "")
+
#
props.sql?.replace(/\s+/g, " ").trim() || "") {{ col }} - #{{ columnTypeMap.get(col) }} + #{{ columnTypeMap.get(col) }}
props.sql?.replace(/\s+/g, " ").trim() || "") key-field="id" @scroll="syncHeaderScroll" > -