---
title: "TableColumns"
description: "Sort and resize for a table that renders on the server."
canonical: "https://lopifi.com/components/table-columns"
---

# TableColumns

> Sort and resize for a table that renders on the server.

Source: https://lopifi.com/components/table-columns
Part of: Lopifi — Your VC tech stack partner (https://lopifi.com)

---

- **Family:** Ledger & tables — 
- **Status:** Implemented
- **Spec:** https://lopifi.com/docs/catalog/ledger-tables

## Install

```bash
npx shadcn@latest add @lopifi/theme
npx shadcn@latest add @lopifi/table-columns
```

## Specification

> Sortable, resizable columns for a table that renders on the server.

The sibling of `GridKeyboard`, for the same reason. Most ledger tables here are server
components, because a 400-row statement shouldn't ship 400 rows of JavaScript to be rendered
twice. But bookkeepers come from Excel, where every column sorts and drags, and rewriting
nineteen tables as client components is the worse trade.

So it wraps the table the server produced instead of replacing it. Header cells become sort
controls with a resize handle, an injected (or adopted) `<colgroup>` carries the widths, and
rows are reordered in place. Any table in the catalog gets both behaviors without knowing this
component exists.

```tsx
<TableColumns storageKey="gl-detail" onOpenRow={(i) => setDrilldown(i)}>
  <GridKeyboard>
    <LedgerTable … />
  </GridKeyboard>
</TableColumns>
```

### Sorting
- **Three states, not two**: ascending, descending, and back to the ledger's own order.
  A journal's source order is information, and a table you can't un-sort loses it.
- **Numbers and dates open at the big end, text opens at A.** The question behind
  clicking an amount column is "what's the largest", never "what's the smallest", and a
  first click that shows the oldest row looks like a bug.
- **Sorts the value, not the presentation**: `data-sort`, then the `data-raw` that
  `Money` already stamps, then the text. Sorted as text, `($1,240.56)` sorts by its
  opening parenthesis.
- **`null` is not `0`.** Blanks sort last in *both* directions. Flip them to the top on a
  descending sort and a reviewer concludes twelve accounts have no balance, when the
  balances just aren't known yet.
- **Stable.** Rows that tie keep the order the ledger gave them — date, then entry number.
- **Status columns sort by workflow, not alphabet.** A–Z puts `cancelled` above `overdue`.

### What it refuses to sort
- **A hierarchy.** `data-level` rows (a chart of accounts) or `data-row-variant` rows
  (subtotals, section heads) carry meaning in their order. A subtotal floating away from
  the rows it totals is worse than an unsorted table. Those tables still resize.
- **A table that opted out.** `data-sortable="false"` on the `<table>`, set by the
  component, not the caller. A register's running balance only means something in date
  order, and the register knows that.
- **`tfoot`.** Totals are not rows of the population.
- **A page of a larger set.** Sorting the page answers "largest amount" with the largest
  of ninety-four rows out of twelve thousand, and it looks exactly right. Pass
  `sortable={false}` and sort at the source.

### Resizing
Account names, memos and vendor names have no natural length. The width that fits one
client's chart of accounts truncates another's on every row, and two truncated account
names look identical. That's a correctness problem, not just a layout one.

- **A 9px hit area centered on the seam**, with a 1px line that paints only on hover,
  focus or drag. A visible grabber on every boundary turns a ledger into a grid of
  handles.
- **The handle is a real `separator`** with `aria-valuenow`. Arrows move it 16px,
  `Alt`+arrows 1px, and `Home` or a double-click restores the shipped width.
- **Measured from the start of the drag**, never accumulated per move, which drifts
  away from the cursor.
- **Persisted per user per table** on pointer-up, never per move. Stored widths are
  clamped to today's bounds and dropped for columns that no longer exist, because the
  table's shape outlives the preference.
- **The slack goes to one column**, the widest at first paint, which is reliably the
  label column. A fixed-layout table narrower than its card leaves a gap, and a ruled
  card with a gap looks like a rendering bug.
- **A body cell clips; a figure cell does not.** A truncated label is an inconvenience
  the reader can undo. A figure missing its leading digit is wrong.

### Row detail
`onOpenRow` fires on double-click and on `Enter`. People bring double-click from every
ledger they've used, and `Enter` works without a mouse. Pair it with `DrilldownSheet` or `TransactionDetail`.

## Rules this component obeys

Money is minor units, never floats. `null` is not `0` and neither is redacted. Negatives render in accounting parentheses with the parenthesis column reserved on both sides. Debit and credit are two columns. Per-currency decimal places. Polarity is explicit — up is not always good. Every figure states its period, entity, currency, basis and as-of.
