Skip to content

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

fix: cell width (#18413)

ecmadao769fba98e590
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 4cbd9e3a31..975c9062b3 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
@@ -7,7 +7,7 @@
<table
ref="tableRef"
class="relative border-collapse -mx-px"
- v-bind="tableResize.tableProps"
+ v-bind="tableResize.getTableProps()"
>
<thead
class="bg-gray-50 dark:bg-gray-700 sticky top-0 z-1 drop-shadow-xs"
@@ -16,16 +16,16 @@
<!-- header for the index -->
<th
:key="`${setIndex}-0-index`"
- class="`group relative px-2 py-2 tracking-wider border-x border-block-border dark:border-zinc-500"
+ class="group relative py-2 shrink-0 tracking-wider border-x border-block-border dark:border-zinc-500 w-px whitespace-nowrap"
v-bind="tableResize.getColumnProps(0)"
>
<!-- Use the max index to calculate the cell width -->
<div
:class="[
- 'textinfolabel opacity-0',
+ 'textinfolabel pr-1 opacity-0',
selectionDisabled
- ? ''
- : 'ml-2',
+ ? 'pl-1'
+ : 'pl-4',
]"
>{{ rows.length }}</div>
<div
@@ -38,8 +38,9 @@
<th
v-for="(header, columnIndex) of columns"
:key="`${setIndex}-${columnIndex + 1}-${header.id}`"
- class="group relative px-3 py-2 min-w-8 text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-x border-block-border dark:border-zinc-500"
+ class="group relative px-3 py-2 min-w-8 text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-block-border dark:border-zinc-500"
:class="{
+ 'border-r': columnIndex < (columns.length - 1),
'cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800':
!selectionDisabled,
'bg-accent/10! dark:bg-accent/40!':
@@ -110,7 +111,6 @@
ref="virtualListRef"
:items="rows"
:item-size="ROW_HEIGHT"
- :style="{ width: `${tableResize.totalWidth.value}px` }"
>
<template #default="{ item: row, index: rowIndex }: { item: { item: QueryRow; }; index: number; }">
<div
@@ -124,7 +124,7 @@
<!-- the index cell -->
<div
:key="`${setIndex}-${rowIndex}-0`"
- class="relative flex items-center pl-3 shrink-0 text-sm dark:text-gray-100 leading-5 whitespace-nowrap break-all border-block-border dark:border-zinc-500 group-even:bg-gray-100/50 dark:group-even:bg-gray-700/50"
+ class="relative flex items-center shrink-0 text-sm dark:text-gray-100 leading-5 whitespace-nowrap break-all border-block-border dark:border-zinc-500 group-even:bg-gray-100/50 dark:group-even:bg-gray-700/50"
:class="{
'border-r': true,
'border-b': true,
@@ -139,10 +139,10 @@
>
<NPerformantEllipsis
:class="[
- 'overflow-hidden textinfolabel',
+ 'textinfolabel pr-1',
selectionDisabled
- ? ''
- : 'ml-2',
+ ? 'pl-1'
+ : 'pl-4',
]"
>
{{ rowIndex + 1 }}
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 765e8889c3..5ad5c0f3b9 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
@@ -64,14 +64,51 @@ const useTableResize = (options: TableResizeOptions) => {
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 }));
+ const lastIndex = thList.length - 1;
+
+ // First pass: calculate base widths for all columns except the last
+ const baseWidths = thList.map((th, index) => {
+ // For the first column (index column), use scrollWidth to get exact content width
+ if (index === 0) {
+ const content = th.firstElementChild as HTMLElement | null;
+ if (content) {
+ // scrollWidth gives the content width (includes padding but not margin)
+ const thStyle = getComputedStyle(th);
+ const contentStyle = getComputedStyle(content);
+ const borderLeft = parseFloat(thStyle.borderLeftWidth) || 0;
+ const borderRight = parseFloat(thStyle.borderRightWidth) || 0;
+ const marginLeft = parseFloat(contentStyle.marginLeft) || 0;
+ const marginRight = parseFloat(contentStyle.marginRight) || 0;
+ return (
+ content.scrollWidth +
+ borderLeft +
+ borderRight +
+ marginLeft +
+ marginRight
+ );
+ }
+ }
+ const width = th.getBoundingClientRect().width;
+ return Math.max(width, width * scale);
+ });
+
+ // For the last column, subtract any extra width that was added to fill container
+ const containerW = options.containerRef?.value?.clientWidth || 0;
+ const sumWithoutLast = baseWidths
+ .slice(0, lastIndex)
+ .reduce((a, b) => a + b, 0);
+ const lastColWidth = baseWidths[lastIndex];
+ const expectedTotal = sumWithoutLast + lastColWidth;
+ // If table was expanded to fill container, remove that extra from last column
+ if (expectedTotal > containerW && lastColWidth > options.minWidth) {
+ const extraWidth = expectedTotal - containerW;
+ baseWidths[lastIndex] = Math.max(
+ options.minWidth,
+ lastColWidth - extraWidth
+ );
+ }
+
+ state.columns = baseWidths.map((width) => ({ width }));
// After calculating the width, use fixed layout to keep the width stable.
state.isAutoAdjusting = false;
});
@@ -89,8 +126,18 @@ const useTableResize = (options: TableResizeOptions) => {
index,
initialWidth: actualWidth,
};
- // Sync state with actual DOM width
- state.columns[index].width = actualWidth;
+ // Sync state with actual DOM width, but for the last column,
+ // exclude the extra space that was added to fill the container
+ const isLastColumn = index === state.columns.length - 1;
+ if (isLastColumn) {
+ const containerW = options.containerRef?.value?.clientWidth || 0;
+ const total = sumBy(state.columns, (col) => col.width);
+ const extraWidth = Math.max(0, containerW - total);
+ // Store actual width minus extra space
+ state.columns[index].width = actualWidth - extraWidth;
+ } else {
+ state.columns[index].width = actualWidth;
+ }
toggleDragStyle(table, true);
};
@@ -122,7 +169,21 @@ const useTableResize = (options: TableResizeOptions) => {
const getColumnProps = (index: number) => {
const column = state.columns[index];
if (!column) return {};
- const widthValue = state.isAutoAdjusting ? "auto" : `${column.width}px`;
+ // For the first column (index column), use "1px" during auto-adjusting to shrink to content
+ const autoWidth = index === 0 ? "1px" : "auto";
+
+ // Calculate actual width including extra space for the last column
+ let actualWidth = column.width;
+ if (!state.isAutoAdjusting) {
+ const containerW = options.containerRef?.value?.clientWidth || 0;
+ const total = sumBy(state.columns, (col) => col.width);
+ const extraWidth = Math.max(0, containerW - total);
+ if (extraWidth > 0 && index === state.columns.length - 1) {
+ actualWidth = column.width + extraWidth;
+ }
+ }
+
+ const widthValue = state.isAutoAdjusting ? autoWidth : `${actualWidth}px`;
return {
style: {
width: widthValue,
@@ -137,22 +198,45 @@ const useTableResize = (options: TableResizeOptions) => {
const getColumnWidth = (index: number): number => {
const column = state.columns[index];
- return column?.width ?? 0;
+ if (!column) return 0;
+
+ // When effectiveWidth > totalWidth, add extra space to the last column
+ const containerW = options.containerRef?.value?.clientWidth || 0;
+ const total = sumBy(state.columns, (col) => col.width);
+ const extraWidth = Math.max(0, containerW - total);
+
+ // Add extra width to the last column
+ if (extraWidth > 0 && index === state.columns.length - 1) {
+ return column.width + extraWidth;
+ }
+
+ return column.width;
};
const totalWidth = computed(() => {
return sumBy(state.columns, (col) => col.width);
});
- const tableProps = computed(() => {
- const widthValue = state.isAutoAdjusting ? "auto" : `${totalWidth.value}px`;
+ // Effective width is the max of totalWidth and container width
+ const effectiveWidth = computed(() => {
+ const containerW = options.containerRef?.value?.clientWidth || 0;
+ return Math.max(totalWidth.value, containerW);
+ });
+
+ const getTableProps = () => {
+ const widthValue = state.isAutoAdjusting
+ ? "auto"
+ : `${effectiveWidth.value}px`;
+ const tableLayout: "auto" | "fixed" = state.isAutoAdjusting
+ ? "auto"
+ : "fixed";
return {
style: {
width: widthValue,
- tableLayout: state.isAutoAdjusting ? "auto" : "fixed",
+ tableLayout,
},
};
- });
+ };
onBeforeUnmount(() => {
toggleDragStyle(table, false);
@@ -162,7 +246,7 @@ const useTableResize = (options: TableResizeOptions) => {
reset,
getColumnProps,
getColumnWidth,
- tableProps,
+ getTableProps,
totalWidth,
startResizing,
};