Skip to content

feat(data-grid): double-click a column border to fit its width - #1339

Merged
debba merged 3 commits into
TabularisDB:mainfrom
Mittalnew:feat/fit-column-width-on-double-click
Oct 29, 2026
Merged

debba merged 3 commits into
TabularisDB:mainfrom
Mittalnew:feat/fit-column-width-on-double-click

Conversation

@Mittalnew

Copy link
Copy Markdown
Contributor

Closes #1295

Double-clicking a column resize handle now fits that column to its header and the loaded rows, within the existing minimum and maximum column widths. Only that column changes. The header context menu also has a new "Reset column widths" entry that drops the manual widths and goes back to the automatic layout.

Changes:

  • getFitColumnWidth helper in utils/columnResize.ts, with unit tests
  • ColumnResizeHandle takes an optional onDoubleClick prop; the event does not reach the header, so it does not sort or select the column
  • DataGrid measures cell values on a canvas, using the font and padding of a rendered cell in that column (with the current defaults as a fallback), and measures the header at its natural width, so the table does not reflow
  • "Reset column widths" in the header context menu, translated in all locales
  • DataGrid tests for fitting a column, fitting a frozen first column and resetting the widths

Keyboard resizing on the focused handle works as before.

// Double-clicking a resize handle fits that column to its header and the
// loaded rows (#1295). Cells are measured on a canvas with the result font,
// so the table never reflows; the header is measured at its natural width.
// Double-clicking a resize handle fits that column to its header and the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Duplicated comment block

The second commit added a second copy of the "Double-clicking a resize handle..." comment directly under the first one (lines 1636-1638). Remove one of them (the older one also states the canvas uses "the result font", which is no longer accurate since the font is now read from a rendered cell).

`tbody td[data-col-index="${colIndex}"]`,
) ?? null;
const cellStyle = sampleCell ? getComputedStyle(sampleCell) : null;
ctx.font = cellStyle?.fontSize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Fit width is measured against the wrong text metrics when no rows are rendered/virtualized in the column

sampleCell is the first rendered tbody td of the column. If the grid is empty or only padding rows are rendered, cellStyle is null and the fallback uses a hard-coded 14px plus FIT_COLUMN_PADDING = 33, ignoring the font-size setting the comment on line 1650 says must be followed. Also, ${cellStyle.fontWeight} ${cellStyle.fontSize} ${cellStyle.fontFamily} is measured with the body cell font while the header text (text-xs font-semibold tracking-wider) is measured through DOM, so that part is fine; but cell values rendered with a different font (e.g. monospace for JSON/numbers via a nested element) would be mis-measured. Consider measuring from the inner content element of the cell rather than the td.

/>
</tr>
)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unrelated whitespace change

This added blank line is unrelated to the feature; drop it to keep the diff focused.

import {SetCellsValueModal} from '@/components/modals/SetCellsValueModal';
import {KeybindingsContext} from '@/contexts/KeybindingsContext';

/** Horizontal padding of a grid cell (px-4 on both sides) plus its 1px border. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Missing blank lines around the new constant

The blank line that previously separated the imports from DataGridCommandTarget was removed, so the new doc comment/constant is glued to the import block and to the following export interface. Restore blank lines before and after FIT_COLUMN_PADDING.

@kilo-code-bot

kilo-code-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/web-ui/src/components/ui/DataGrid.tsx 1657 Cell text is measured using the td font rather than the inner content element, so values rendered with a different font (e.g. monospace via a nested element) may be mis-measured. When no body cell is rendered, the font still falls back to a hard-coded 14px (padding now falls back to the header cell).

SUGGESTION

File Line Issue
packages/web-ui/src/components/ui/DataGrid.tsx 155 No blank line after the new FIT_COLUMN_PADDING constant, which is glued to the following export interface
Files Reviewed (1 file in incremental diff)
  • packages/web-ui/src/components/ui/DataGrid.tsx - 2 issues

Fix these issues in Kilo Cloud

Previous Review Summary (commit f47bdf9)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit f47bdf9)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/web-ui/src/components/ui/DataGrid.tsx 1639 Duplicated "Double-clicking a resize handle..." comment block left by the second commit; the first copy is now inaccurate
packages/web-ui/src/components/ui/DataGrid.tsx 1659 Font/padding fall back to hard-coded 14px/33 when the column has no rendered body cell; the td font is used for measuring rather than the inner content element

SUGGESTION

File Line Issue
packages/web-ui/src/components/ui/DataGrid.tsx 3324 Unrelated blank-line addition
packages/web-ui/src/components/ui/DataGrid.tsx 154 Blank lines around the new FIT_COLUMN_PADDING constant were removed, gluing it to the imports and the following export interface
Files Reviewed (16 files)
  • packages/web-ui/src/components/ui/ColumnResizeHandle.tsx
  • packages/web-ui/src/components/ui/DataGrid.tsx - 4 issues
  • packages/web-ui/src/utils/columnResize.ts
  • packages/web-ui/src/i18n/locales/*.json (11 locales)
  • packages/web-ui/tests/components/ui/DataGrid.test.tsx
  • packages/web-ui/tests/utils/columnResize.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5.5 · Input: 250 · Output: 1.8K · Cached: 171.1K

Review guidance: REVIEW.md from base branch main

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fitting columns using the rendered font and padding, and adding a way to reset manual widths.

Since this is your first PR here, we would be happy to have you join us on Discord if you would like to get involved: https://discord.com/invite/K2hmhfHRSt

I have not found an obvious blocker in the diff. I will run end-to-end checks in the real app for further verification, then proceed with the merge if those checks pass.

@debba

debba commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

I tested this in the real macOS app with a SQLite table containing NULLs, empty strings, multiline text and longer values. Double-click fitting changes only the chosen column, reset restores automatic widths, and fitting a frozen first column and resizing it with the keyboard both work. No console errors appeared. Typecheck, formatting, theme checks and ESLint excluding local worktrees and generated bundles pass; full suites show only the failures reproduced on main. Ready to merge.

@debba
debba merged commit 569cde1 into TabularisDB:main Oct 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Data grid: double-click a column border to fit its width to the content

2 participants