Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: table resize (#18403)

ecmadao8caf13e94dc2
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
index 8ef4fbf547..4cbd9e3a31 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
@@ -3,11 +3,12 @@
ref="containerRef"
class="relative w-full flex-1 overflow-auto flex flex-col rounded-sm border dark:border-zinc-500"
>
- <table
- ref="tableRef"
- class="relative border-collapse w-full -mx-px table-fixed"
- v-bind="tableResize.tableProps"
- >
+ <div class="inline-block">
+ <table
+ ref="tableRef"
+ class="relative border-collapse -mx-px"
+ v-bind="tableResize.tableProps"
+ >
<thead
class="bg-gray-50 dark:bg-gray-700 sticky top-0 z-1 drop-shadow-xs"
>
@@ -103,7 +104,8 @@
</th>
</tr>
</thead>
- </table>
+ </table>
+ </div>
<NVirtualList
ref="virtualListRef"
:items="rows"
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
index f16254b32f..765e8889c3 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
@@ -56,36 +56,41 @@ const useTableResize = (options: TableResizeOptions) => {
if (!table.value) return;
state.drag = undefined;
- state.isAutoAdjusting = false;
-
// Use auto layout to calculate the width of each column.
- table.value.style.tableLayout = "auto";
- const scale = containerWidth.value / table.value.scrollWidth;
- const thList = Array.from(table.value.querySelectorAll("th"));
- state.columns = thList
- .map((th) =>
- Math.max(
- th.getBoundingClientRect().width,
- th.getBoundingClientRect().width * scale
- )
- )
- .map((width) => ({ width }));
- // After calculating the width, use fixed layout to keep the width stable.
+ state.isAutoAdjusting = true;
+
nextTick(() => {
- if (!table.value) {
- return;
- }
- table.value.style.tableLayout = "fixed";
+ if (!table.value) return;
+
+ const scale = containerWidth.value / table.value.scrollWidth;
+ const thList = Array.from(table.value.querySelectorAll("th"));
+ state.columns = thList
+ .map((th) =>
+ Math.max(
+ th.getBoundingClientRect().width,
+ th.getBoundingClientRect().width * scale
+ )
+ )
+ .map((width) => ({ width }));
+ // After calculating the width, use fixed layout to keep the width stable.
+ state.isAutoAdjusting = false;
});
};
// Record the initial state of dragging.
const startResizing = (index: number) => {
+ // Use actual DOM width as the initial width to ensure accuracy
+ const th = table.value?.querySelectorAll("th")[index];
+ const actualWidth =
+ th?.getBoundingClientRect().width ?? state.columns[index].width;
+
state.drag = {
start: pointer.x.value,
index,
- initialWidth: state.columns[index].width,
+ initialWidth: actualWidth,
};
+ // Sync state with actual DOM width
+ state.columns[index].width = actualWidth;
toggleDragStyle(table, true);
};
@@ -99,6 +104,7 @@ const useTableResize = (options: TableResizeOptions) => {
const offset = pointer.x.value - start;
const expectedWidth = initialWidth + offset;
state.columns[index].width = normalizeWidth(expectedWidth);
+
if (index === state.columns.length - 1) {
// When resizing the last column, Keep the horizontal scroll at the end of the container.
scrollMaxX(options.containerRef.value);
@@ -116,9 +122,13 @@ const useTableResize = (options: TableResizeOptions) => {
const getColumnProps = (index: number) => {
const column = state.columns[index];
if (!column) return {};
+ const widthValue = state.isAutoAdjusting ? "auto" : `${column.width}px`;
return {
style: {
- width: state.isAutoAdjusting ? "auto" : `${column.width}px`,
+ width: widthValue,
+ minWidth: widthValue,
+ maxWidth: widthValue,
+ boxSizing: "border-box" as const,
},
class: state.isAutoAdjusting ? "" : "truncate",
"data-index": index,
@@ -135,9 +145,11 @@ const useTableResize = (options: TableResizeOptions) => {
});
const tableProps = computed(() => {
+ const widthValue = state.isAutoAdjusting ? "auto" : `${totalWidth.value}px`;
return {
style: {
- width: state.isAutoAdjusting ? "auto" : `${totalWidth.value}px`,
+ width: widthValue,
+ tableLayout: state.isAutoAdjusting ? "auto" : "fixed",
},
};
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue b/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue
index fb2ed4a756..1f2f70bc65 100644
--- a/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue
@@ -1,5 +1,7 @@
<template>
- <EngineIcon v-if="connected && instance" :engine="instance.engine" />
+ <div v-if="connected && instance" class="w-4">
+ <EngineIcon custom-class="w-full" :engine="instance.engine" />
+ </div>
<UnlinkIcon v-else />
</template>