Skip to content

feat(grid): freeze the first data column while scrolling horizontally - #1234

Merged
debba merged 3 commits into
TabularisDB:mainfrom
Detoy:feat/freeze-first-column-1152
Oct 26, 2026
Merged

debba merged 3 commits into
TabularisDB:mainfrom
Detoy:feat/freeze-first-column-1152

Conversation

@Detoy

@Detoy Detoy commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1152

Problem

The row-number gutter is already sticky, but the first data column scrolls away with the rest. On a wide result you lose the identifier (id, a code, an email) as soon as you scroll right to read the other columns.

Fix

Toggle. The column header context menu gets Freeze first column / Unfreeze first column (Pin / PinOff icon), next to Select Column. It's grid-local useState in DataGrid: one column only, nothing persisted, off by default.

Sticky offsets (getFrozenFirstColumnLayout, pure)

  • The frozen header and body cells use position: sticky with left = the gutter's width minus its 1px shared border, read from the column widths the grid already measures and locks (50px until they're measured, so left: 49px). That keeps the header, cells and gutter aligned under horizontal and vertical scrolling.
  • Why minus 1px: with border-collapse, the border between the gutter and the first column is painted by the table where the column started, outside the sticky cell's own painting. At left = gutter width, a 1px column of scrolled text showed through that strip. Pulling the frozen cell 1px under the gutter covers it.
  • Stacking: body cell z-[5] (above scrolling cells, below the gutter's z-10), header z-[15] (below the gutter header's z-20).

Opaque backdrop (getFrozenCellBackdropClass, pure)

  • Row and cell tints are translucent, so a plain sticky cell would show the cells scrolling under it. The frozen cell paints two layers under its content:
    • ::before is the row background pre-mixed over the grid background (color-mix(... var(--bg-elevated)) with the same token and percentage as the row: selected, insertion, pending delete, zebra, and the hover tints). It mirrors the row's class precedence.
    • ::after is background-color: inherit, which repaints the cell's own tint (edited, column or range selection) on top.
  • Collapsed table borders stay where the column started, so ::before (inset-0) also draws the frozen column's right border.
  • Masked cells render as before; the change only affects the backdrop.

Editing and focus

  • An editing cell normally switches to position: relative to anchor the inline editor. A frozen cell skips that (sticky already anchors it), so it stays frozen while you edit.
  • The focus mark on a frozen cell is an outline rather than the inset ring, because a box-shadow ring is painted under the backdrop layers.

Keyboard navigation

  • While frozen, the scroll container gets scroll-padding-left = gutter + frozen column width, so scrollIntoView stops the active cell to the right of the frozen column, where it was otherwise hidden under it.
  • That padding would also make the browser scroll back to the start whenever the frozen cell itself got focus. The focus effect keeps scrollLeft for the frozen column, and its editor is focused with preventScroll.

Column resizing (#1222)

  • Every header is relative so the resize handle can sit inside it. The frozen header is sticky instead, which is already the handle's containing block, so it keeps its handle and the two classes don't fight over position.
  • The frozen column's left is the gutter width, which resizing never changes. Its scroll padding is computed from the locked widths, so it follows the new width when a resize is committed (mouse up or a key press). During a drag only the <col> width is painted, and the sticky cell follows it.
Frozen, scrolled right After dragging the frozen column 80px wider

Screenshots

Component preview in Chrome: the real DataGrid with simulated rows, a selected row (2), a pending edit (row 3) and zebra stripes, scrolled right.

Before (main), scrolled right After, frozen and scrolled right
Header menu After, light theme
Keyboard: ArrowLeft stops right of the frozen column Focused frozen cell keeps the scroll position Editing a frozen cell

Manual wide-result check in that preview (Chrome, measured with getBoundingClientRect): the frozen header and cells sit at 50–164px at every horizontal and vertical scroll position. Scrolled right, walking ArrowLeft from column 8 to column 1 always leaves the focused cell to the right of the frozen column. Clicking, ArrowDown in and double-clicking the frozen cell all keep scrollLeft at 400.

Gutter edge, 6× zoom (left: d51fe99f, left = gutter width; right: this branch). A pixel check that diffs screenshots with and without the scrolled cells' text, at 5 scroll positions in both themes, went from 564 leaked device pixels to 150. The remaining 150 all come from the selected row's translucent gutter described below, which is the same on main.

After, dark (rebased) After, light (rebased)

Testing

  • Tests written first and seen failing:
    • packages/web-ui/tests/utils/dataGrid.test.ts: 7 cases for the offsets (fallback and measured widths) and the backdrop (default, zebra, precedence of selected > insertion > pending delete, no hover tint on those states, tint layer present).
    • packages/web-ui/tests/components/ui/DataGrid.test.tsx, new DataGrid freeze first column (#1152) block, 6 cases: freeze and unfreeze from the header menu (only column 0 gets sticky, left: 49px), scroll padding on and off, a frozen cell stays sticky while edited, its editor is focused with preventScroll, focusing it keeps scrollLeft, and the outline focus mark.
  • Rebased onto main 39dab01 (after feat(grid): resize columns with the mouse and keyboard #1222 added column resizing). Both sides of the helper and test conflicts are kept. New test in the #1151 resizing block: a frozen first column keeps its resize handle (sticky, not relative), and dragging or arrow-keying it keeps left at the gutter edge while scroll-padding-left follows the new width. I checked it fails if the frozen header is also relative.
  • vitest run --config packages/web-ui/vitest.config.ts: 459 files, 7336 tests pass. tsc -b, Prettier and eslint on the changed files, and the theme token check are clean.
  • In Chrome (component preview, frozen and scrolled 400px right): dragging the frozen column's handle 80px wider moved it from 114px to 194px, its left edge stayed at the gutter, and the scroll padding went to 244px (50 + 194). Shift+ArrowLeft on the handle took it to 144px and the padding to 194px. Walking left with the arrow keys from column 8 kept every focused cell to the right of the frozen column.
  • Impact: MemoRow is only rendered by DataGrid, and RowCtx gains one field. With the toggle off, the cells, header and scroll container render the same classes as on main. The only shared-path change is the edit-focus effect, which now passes { preventScroll: false } (the default) for every cell that isn't frozen. No backend change, 2 new strings in all 11 locales.

Plugin drivers

Driver-independent: it only changes how the loaded result set is rendered, so it behaves the same for every built-in and plugin driver.

Not in this PR

  • Only the first data column can be frozen, and the choice isn't persisted, as the issue scopes it.
  • The gutter's own background for selected rows is translucent on main (bg-accent-primary/20), so scrolled text still shows faintly through the gutter of a selected row (visible in both Before and After). I left that alone; happy to send a follow-up if you want it opaque too.
  • The frozen state is plain useState in DataGrid, so it survives running a new query in the same tab (the grid isn't remounted). It resets when the tab closes.
  • scroll-padding-left uses the 50px fallback until the widths are measured, i.e. for the first frame only.
  • The focus ring still uses outline-accent-primary, like the existing non-frozen ring; switching both to outline-focus is left for a follow-up.
  • I haven't run it in the desktop app (WebKitGTK/WebView2). The screenshots, measurements and the pixel check below come from Chrome.

AI disclosure: I built this with AI assistance (Grok Bot) and reviewed the diff, tests and screenshots before opening the PR.

@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

This update adds one commit (9ba84d21) on top of the previously reviewed state. It is test-only: a new case in the DataGrid column resizing (#1151) suite that resizes a frozen first column.

I checked the new test against the implementation. With a measured gutter of 100px, the frozen header and cells get left: 99px and the grid gets scrollPaddingLeft: 200px. After resizing the column to 160px, left stays at 99px and the padding becomes 260px. The renderGrid, col, separators and MEASURED helpers are all in scope. The sticky/relative class assertions also match how DataGrid.tsx builds the header class. No production code changed, and the earlier findings still hold: none.

Assumption: I did not run the tests or the visual behavior. The PR notes it was only verified in Chrome, so a quick check in WebKitGTK and WebView2 is worthwhile.

Files Reviewed (16 files)
  • packages/web-ui/src/components/ui/DataGrid.tsx
  • packages/web-ui/src/components/ui/DataGridRow.tsx
  • packages/web-ui/src/utils/dataGrid.ts
  • packages/web-ui/src/i18n/locales/de.json
  • packages/web-ui/src/i18n/locales/en.json
  • packages/web-ui/src/i18n/locales/es.json
  • packages/web-ui/src/i18n/locales/fr.json
  • packages/web-ui/src/i18n/locales/it.json
  • packages/web-ui/src/i18n/locales/ja.json
  • packages/web-ui/src/i18n/locales/ko.json
  • packages/web-ui/src/i18n/locales/pt-BR.json
  • packages/web-ui/src/i18n/locales/ru.json
  • packages/web-ui/src/i18n/locales/tl.json
  • packages/web-ui/src/i18n/locales/zh.json
  • packages/web-ui/tests/components/ui/DataGrid.test.tsx
  • packages/web-ui/tests/utils/dataGrid.test.ts
Previous Review Summaries (3 snapshots, latest commit 0c261d0)

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

Previous review (commit 0c261d0)

Status: No Issues Found | Recommendation: Merge

This update rebases onto the packages/web-ui layout and adds one commit (0c261d0b) that fixes the 1px strip of scrolled text at the gutter edge. getFrozenFirstColumnLayout now sets the frozen column's sticky left to the gutter width minus the 1px collapsed border, so it sits under the gutter and covers the strip. scrollPaddingLeft still uses the full gutter width, and the ::before backdrop is now plain inset-0.

I checked the stacking: the gutter body cell is z-10 and the header gutter is z-20. These sit above the frozen body cell (z-[5]) and frozen header (z-[15]), so the 1px overlap is hidden. The updated tests (49px and 57px for left, unchanged scroll padding) match the new values. The rest of the PR is unchanged from the previous review.

Assumption: I did not run the visual behavior. The PR notes it was only verified in Chrome, so a quick check in WebKitGTK and WebView2 is worthwhile.

Files Reviewed (16 files)
  • packages/web-ui/src/components/ui/DataGrid.tsx
  • packages/web-ui/src/components/ui/DataGridRow.tsx
  • packages/web-ui/src/utils/dataGrid.ts
  • packages/web-ui/src/i18n/locales/de.json
  • packages/web-ui/src/i18n/locales/en.json
  • packages/web-ui/src/i18n/locales/es.json
  • packages/web-ui/src/i18n/locales/fr.json
  • packages/web-ui/src/i18n/locales/it.json
  • packages/web-ui/src/i18n/locales/ja.json
  • packages/web-ui/src/i18n/locales/ko.json
  • packages/web-ui/src/i18n/locales/pt-BR.json
  • packages/web-ui/src/i18n/locales/ru.json
  • packages/web-ui/src/i18n/locales/tl.json
  • packages/web-ui/src/i18n/locales/zh.json
  • packages/web-ui/tests/components/ui/DataGrid.test.tsx
  • packages/web-ui/tests/utils/dataGrid.test.ts

Previous review (commit d51fe99)

Status: No Issues Found | Recommendation: Merge

This update is a rebase onto the Prettier formatting commit (44270cab), which is why the diff against the previously reviewed SHA is whitespace-heavy across the repo. Against the new base, the PR still touches the same 16 files and the code is unchanged in substance: sticky header/cells for the frozen first column with an opaque ::before/::after backdrop, scroll padding for keyboard navigation, preventScroll on the editor focus, and the two new locale strings in all 11 locales. No new issues found, and no earlier findings carry over.

Assumption: the visual behavior (the 1px gutter-edge overlap on cells that use truncate, WebKit/WebView2 rendering) was not run here. The PR notes it was only verified in Chrome, so a quick manual check in the desktop app is worthwhile.

Files Reviewed (16 files)
  • src/components/ui/DataGrid.tsx
  • src/components/ui/DataGridRow.tsx
  • src/utils/dataGrid.ts
  • src/i18n/locales/de.json
  • src/i18n/locales/en.json
  • src/i18n/locales/es.json
  • src/i18n/locales/fr.json
  • src/i18n/locales/it.json
  • src/i18n/locales/ja.json
  • src/i18n/locales/ko.json
  • src/i18n/locales/pt-BR.json
  • src/i18n/locales/ru.json
  • src/i18n/locales/tl.json
  • src/i18n/locales/zh.json
  • tests/components/ui/DataGrid.test.tsx
  • tests/utils/dataGrid.test.ts

Previous review (commit 965b5f1)

Status: No Issues Found | Recommendation: Merge

Reviewed the freeze-first-column change (sticky header/cells with opaque ::before/::after backdrop, scroll padding for keyboard navigation, preventScroll on the editor focus, and the new locale strings). The backdrop classes mirror the row classes in DataGridRow.tsx in the same precedence, colors come from theme tokens, and all 11 locales have the two new keys. Tests cover the new layout/backdrop helpers and the grid behavior.

Assumption: the visual behavior (the 1px gutter-edge overlap on cells that use truncate, WebKit/WebView2 rendering) was not run here. The PR notes it was only verified in Chrome, so a quick manual check in the desktop app is worthwhile.

Files Reviewed (16 files)
  • src/components/ui/DataGrid.tsx
  • src/components/ui/DataGridRow.tsx
  • src/utils/dataGrid.ts
  • src/i18n/locales/de.json
  • src/i18n/locales/en.json
  • src/i18n/locales/es.json
  • src/i18n/locales/fr.json
  • src/i18n/locales/it.json
  • src/i18n/locales/ja.json
  • src/i18n/locales/ko.json
  • src/i18n/locales/pt-BR.json
  • src/i18n/locales/ru.json
  • src/i18n/locales/tl.json
  • src/i18n/locales/zh.json
  • tests/components/ui/DataGrid.test.tsx
  • tests/utils/dataGrid.test.ts

Reviewed by claude-sonnet-5.5 · Input: 252 · Output: 2K · Cached: 305.1K

Review guidance: REVIEW.md from base branch main

@Detoy
Detoy force-pushed the feat/freeze-first-column-1152 branch from 965b5f1 to d51fe99 Compare October 21, 2026 13:57
@Detoy

Detoy commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (44270ca) to clear the conflicts from #1247. The behavior is unchanged. This PR's changed files now use the @/ imports and pass the new Prettier check. On d51fe99f, the grid tests pass (312), and tsc -b and eslint are clean.

@github-actions

Copy link
Copy Markdown
Contributor

Preview build

The preview build of commit d51fe99 failed (skipped). See the workflow run for logs.

@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 this, it's a feature people have been asking for! Keeping the layout and background logic in pure helpers (getFrozenFirstColumnLayout, getFrozenCellBackdropClass) with direct tests makes it easy to review. The backdrop follows the same row precedence as DataGridRow (selected, then insertion, pending delete, zebra and hover). The scroll-padding-left, so arrow keys don't park the active cell under the frozen column, is a nice detail.

I'm requesting changes only for the rebase: #676 moved the frontend to packages/web-ui/src and the tests to packages/web-ui/tests. The code you touch hasn't changed on main, so once the paths are rewritten the hunks apply cleanly, and the DataGrid tests pass on the rebased tree.

Nits for a follow-up:

  • Looking closely at your after-frozen-dark.png, I think there's a 1px strip of scrolled text showing at the edge between the row number column and the frozen column (rows 3, 4 and 12), so the before:-left-px cover may not fully close the gap. Could you check it in the real app (WebKitGTK/WebView2)? The description says it hasn't been run there yet.
  • The focused frozen cell uses outline-accent-primary, but accessibility.md and design.md want outline-focus for focus. The existing non-frozen ring uses accent-primary too, so switching both would be great.
  • Before the widths are measured, scrollPaddingLeft is only 50, so in the very first frame keyboard navigation could still hide a cell. It's very short-lived.
  • The frozen state survives a new query in the same tab, since it's plain useState. That's fine, but worth mentioning in the PR.

@Detoy
Detoy force-pushed the feat/freeze-first-column-1152 branch from d51fe99 to 0c261d0 Compare October 23, 2026 14:05
@Detoy

Detoy commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @debba. Rebased onto main 3de43f9, so everything now sits under packages/web-ui/src and packages/web-ui/tests. The original commit is kept as is, and the 1px fix is a separate commit on top (0c261d0).

1px strip at the gutter edge. You were right, and it was the collapsed border. With border-collapse, the 1px border between the gutter and the first column is painted by the table where the column started, outside the sticky cell. Neither the ::before at -1px nor a box-shadow on either cell reached it. So the frozen cell's left is now the gutter width minus that 1px border (49px with the 50px fallback). It sits under the gutter's edge and covers the strip, and ::before is now plain inset-0. I diffed screenshots with and without the scrolled cells' text at 5 scroll positions in both themes: leaked pixels went from 564 to 150. The remaining 150 are the selected row's translucent gutter (bg-accent-primary/20), which is the same on main. There's a 6× zoom of before and after in the description. I only had Chrome here, so WebKitGTK and WebView2 are still unchecked.

outline-focus, first-frame scroll padding. I'll leave both for the follow-up as you suggested, since the focus-ring change also touches the existing non-frozen ring. Both are listed under "Not in this PR".

Frozen state across queries. It's plain useState, so it survives a new query in the same tab. This is now noted in the description.

Full web-ui vitest run: 456 files, 7162 tests pass. Prettier, eslint, the theme-token check and tsc -p packages/web-ui/tsconfig.app.json are all clean.

debba
debba previously approved these changes Oct 23, 2026

@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 the rebase and for tracking down the 1px strip properly. Pulling the frozen cell under the collapsed gutter border is a much cleaner fix than another pseudo-element tweak, and the zoomed before/after in the description made it easy to see what changed.

Everything now sits under packages/web-ui, it still merges cleanly with current main, and the grid and helper tests pass on my side (312, all 13 new freeze cases included). Build, eslint, prettier and the theme token check are clean too. The stacking checks out: the gutter cells stay above the frozen column, so the 1px overlap stays hidden. The note about the frozen state surviving a new query is fine.

I'm approving this. The leftovers are fine as follow-ups, as we said:

  • switch the focus mark to the focus token, both the frozen outline in DataGridRow.tsx and the existing ring
  • the 50px scroll padding before the column widths are measured
  • the translucent gutter on selected rows, if you still feel like sending that one

Since you only had Chrome, I'll run it in the desktop app on my side before merging, mainly to look at the gutter edge and at editing a frozen cell.

@debba

debba commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

@Detoy I merged a batch of approved PRs tonight, and #1222 (column resize with mouse and keyboard) went in just before yours, so this branch now conflicts with main again. Sorry, that one's on the merge order, not on you.

The overlap is real but contained, in four files: DataGrid.tsx, utils/dataGrid.ts and their two test files. In utils/dataGrid.ts both PRs add helpers in the same spot (#1222 added resizeLockedColumn and friends), so keeping both sides should be enough. The header cell in DataGrid.tsx needs a bit more thought: #1222 made every header relative so the resize handle can be positioned inside it, while your frozen header is sticky. Since sticky already creates the containing block for the handle, I think the frozen cell can just use sticky instead of relative and keep the handle.

When you rebase, could you also check that resizing the frozen first column keeps the frozen offset and the scroll padding in sync with the new width? That's the one interaction neither PR could test before.

My approval stands. Once it's rebased and green I'll merge it.

Detoy added 3 commits October 24, 2026 09:27
Adds a grid-local Freeze first column / Unfreeze first column toggle to
the column header context menu (TabularisDB#1152). The frozen header and cells are
sticky right after the row-number gutter, on an opaque backdrop that
repeats the row background (selection, insertion, pending delete, zebra,
hover) so scrolled cells don't show through. Keyboard navigation keeps
the active cell clear of the frozen column through scroll padding, and
focusing or editing a frozen cell no longer scrolls back to the start.
The frozen header keeps the resize handle from TabularisDB#1222: sticky is already
the handle's containing block, so the frozen header is not also made
relative. Resizing the frozen column leaves its sticky offset at the
gutter edge and moves the scroll padding with the new width.
@Detoy
Detoy force-pushed the feat/freeze-first-column-1152 branch from 0c261d0 to 9ba84d2 Compare October 24, 2026 04:12
@Detoy

Detoy commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 39dab01, so it now sits on top of #1222. No worries about the merge order.

  • utils/dataGrid.ts and the two test files: I kept both sides. resizeLockedColumn and getResizedTableWidth sit next to the freeze helpers.
  • Header cell: done as you suggested. The frozen header gets sticky (from FROZEN_HEADER_CELL_CLASS) instead of relative, and every other header stays relative. The resize handle is still inside the frozen header and positions against it.
  • Resizing the frozen column: the sticky left comes from the gutter width, and resizing never changes that. The scroll padding is computed from the same locked widths that resizeLockedColumn updates, so it picks up the new width on commit. During a drag the hook only paints the <col>, and the sticky cell follows it. I added a test to the #1151 block that covers the handle in the frozen header, a drag and an arrow-key resize, checking left and scroll-padding-left after each. It fails if the frozen header is also relative.
  • In Chrome: with the column frozen and the grid scrolled 400px right, I dragged the frozen column from 114px to 194px. Its left edge stayed at the gutter and the padding went to 244px. Shift+ArrowLeft took it to 144px and 194px. Walking left with the arrow keys afterwards kept every focused cell clear of the frozen column. Before and after shots are in the description.

Full vitest run: 459 files, 7336 tests pass. tsc -b, Prettier, eslint on the changed files and the theme token check are clean. Commits: 9ea1334 (feature), f37f019 (1px fix), 9ba84d2 (new test).

@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 handling the overlap with column resizing. The frozen header stays sticky without also becoming relative, and the drag/keyboard test covers the interaction I asked for. The grid and helper suites pass (328 tests), along with typecheck and the frontend checks from my earlier review.

I have now tried the PR in the real macOS app against a wide SQLite table. With the grid scrolled 400px right, dragging the frozen column from about 110px to 190px keeps its left edge at the gutter and changes scroll padding from about 160px to 240px. Shift+ArrowLeft reduces it to 140px with 190px padding. Unfreezing clears the sticky position and padding. Editing the frozen text primary key and clicking Submit persisted the new value in SQLite.

I checked Dark, Light and High Contrast. The frozen cell stays opaque; the existing selected-row gutter issue is visible in Light and High Contrast.

Approved, with these follow-ups:

  • Use the focus token for the frozen outline and the existing focus ring.
  • Revisit the fallback scroll padding before widths are measured.
  • Make the selected-row gutter opaque.
  • Opening the frozen cell's inline editor through a double-click jumps horizontally from scrollLeft=400 to 0 in WKWebView. I repeated that three times with the same result. The edit still saves correctly, so I see this as a scroll/focus follow-up rather than a data-correctness blocker.

The native checks are complete.

@debba
debba merged commit 6ca96f0 into TabularisDB:main Oct 26, 2026
12 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]: Freeze the first data column while scrolling horizontally

2 participants