Skip to content

TableView ​

The rows of one table, a page at a time, filtered and sorted from one command field and editable in place. Edits stay pending until Submit sends them together.

tsx
import { TableView } from '@adecore/database';
tsx
import { TableView } from '@adecore/database';
import { ShopDatabase } from '../shared/database.tsx';
import { SHOP } from '../shared/shop.ts';

export default function TableViewDemo() {
    return (
        <ShopDatabase>
            <div className="flex h-96 w-full overflow-hidden rounded-lg border border-border bg-surface">
                <TableView connection={SHOP} schema="main" table="customers" className="min-w-0 flex-1" />
            </div>
        </ShopDatabase>
    );
}
tsx
<TableView connection={connection} schema="main" table="customers" className="h-full" />

The view fills its parent with a toolbar, the grid and a status bar. A new connection, schema, table, defaultWhere or defaultOrderBy starts it over and drops pending changes. The demo ignores filters and sorts, since fakeDatabaseTransport does not read SQL.

Reading ​

The view loads the table's structure and its first page of rows, 500 by default. Rows per page in the More menu offers 100, 500 and 1000.

A cell draws by its column's kind: numbers align right, NULL reads NULL, binary shows as hex with its size, and long text as a preview. Numbers appear as the server wrote them, unless the provider's numberNotation is 'region'. Before editing a preview, the view fetches the whole value with cell.

Cells, headers and record view field names use the code font at --code-font-size. Console results draw the same grid.

The command field ​

The toolbar field holds filters and sorts as chips before the text. Cmd or Ctrl+F focuses it.

  • Type a column name for suggestions: Filter on, Sort by and Jump to the column.
  • Type a condition, such as quantity > 1, name LIKE 'A%', status IN ('new', 'paid') or country IS NULL, and Enter makes it a chip with the column quoted for the engine.
  • Anything else becomes a raw condition through the last suggestion, Type as SQL.
  • Click a chip to edit it, or a sort chip to flip its direction. Backspace in an empty field removes the last chip. Escape closes the suggestions, then clears the text.

Filters join with AND, and sorts apply in chip order. Every change applies at once, from the first page. The text reaches the server as typed; see Security.

A cell's menu has Filter on (column = value, or IS NULL), Exclude and Sort by. A header's menu sorts or clears the sort. defaultWhere and defaultOrderBy set starting filters, such as a foreign key jump's condition, and override remembered ones.

Paging and counting ​

The status bar shows the rows on the page, the total and the read time. Until counted, the total is a lower bound such as of 501+. Click it to count matching rows with count, which can be slow on a big table; a new filter cancels it. First page and Last page are in the More menu, and Last page counts first when needed. A page of wide rows can hold fewer rows than the page size; Next page continues after the last row shown.

Selecting and copying ​

Click a header to select a column, and Shift or Cmd or Ctrl+click to add more. Shift with arrows or a click selects a block. For several cells, the status bar shows the count and, over the numbers, the sum, average, minimum and maximum.

Cmd or Ctrl+C copies one value, or a block as tab separated text. Copy as in a cell's menu writes TSV, CSV, JSON or SQL INSERT statements.

A copy fetches whole values for previews first, up to 16 MiB. A value it cannot fetch, or a larger selection, is copied as its preview, with a notice.

Drag a header edge to resize a column, or double click it to fit. The header menu hides, pins, copies the name and shows hidden columns.

Editing ​

A cell is editable when the connection, table and column allow it. Enter, F2 or a double click starts an edit. Enter commits, Tab commits and moves on, and Escape cancels. A cell's menu sets NULL or DEFAULT. A MySQL ENUM or SET column edits in a menu of its members.

An edit is pending until Submit:

  • Add row appends an empty row. Untouched columns take their default.
  • Delete marks the selected rows. An unsubmitted new row is removed at once.
  • Cmd or Ctrl+D duplicates the selected or focused rows as new rows. Revert row drops the selected rows' edits.
  • Submit sends every pending change in one apply, all or none. Revert drops them all.
  • An edit back to the original value removes itself.

After a submit the page reloads. If an update or delete matches zero or several rows on the server, nothing is saved, and a banner names the change and its key.

A refresh, page change, new filter or import asks first whether to discard pending changes. onDirtyChange tells the app whether any exist, so it can ask before closing the view.

A schema change for the table's schema reloads the structure and page. With pending changes it shows a banner with Reload instead.

The view finds rows by the row key: the primary key, else the first unique index over non-null columns. Generated columns are read only.

Record view ​

The record view button, or Record view in the More menu, opens one row's fields in a sidebar. It follows the grid's focus. Previous row and Next row, or Cmd or Ctrl+Up and Down, move it and the grid's focus. Drag the left edge to resize; with storage on the provider the width is kept under database:record-view, in pixels.

Fields edit into the same pending changes as the grid. Enter takes the edit, Escape drops it, and Tab or Up and Down move between fields. A foreign key field has an arrow to the referenced row.

Value editor ​

A long text, JSON or binary value expands in place to its whole value. It shows Text, Formatted for JSON, or Hex, Text and UUID for binary, with the binary dump capped at 16 KiB. An editable value changes there, and Apply adds it as a pending edit after checking JSON and hex.

Foreign keys ​

Cmd or Ctrl+click on a foreign key cell, or Go to referenced row in its menu, sends open-table with a where for the referenced row. The record view shows an arrow beside the field. A NULL cell references nothing. Without onAction on the provider none of this is offered.

tsx
import { TableView, type DatabaseAction } from '@adecore/database';
import { useState } from 'react';
import { ShopDatabase } from '../shared/database.tsx';
import { SHOP } from '../shared/shop.ts';

export default function TableViewReferencesDemo() {
    const [action, setAction] = useState<DatabaseAction | null>(null);

    return (
        <ShopDatabase onAction={setAction}>
            <div className="flex w-full flex-col overflow-hidden rounded-lg border border-border bg-surface">
                <div className="flex h-80">
                    <TableView connection={SHOP} schema="main" table="orders" className="min-w-0 flex-1" />
                </div>
                <p className="border-t border-border px-3 py-2 text-xs text-text-muted">
                    {action?.kind === 'open-table'
                        ? `Open ${action.ref.table} where ${action.where ?? 'true'}.`
                        : 'Right click a customer_id and pick Go to referenced row.'}
                </p>
            </div>
        </ShopDatabase>
    );
}

Export and import ​

With files on the provider, the More menu has Export (CSV, TSV, JSON or SQL) and Import from file. An export writes every matching row, not only the page. See Files.

tsx
import { DatabaseProvider, TableView } from '@adecore/database';
import { useEffect, useState } from 'react';
import { createShopClient, SHOP } from '../shared/shop.ts';
import { DEMO_FILES, withDemoFiles } from './demo-files.ts';

export default function TableViewFilesDemo() {
    const [client] = useState(() => withDemoFiles(createShopClient()));

    useEffect(() => () => void client.dispose(), [client]);

    return (
        <DatabaseProvider client={client} files={DEMO_FILES}>
            <div className="flex h-80 w-full overflow-hidden rounded-lg border border-border bg-surface">
                <TableView connection={SHOP} schema="main" table="customers" className="min-w-0 flex-1" />
            </div>
        </DatabaseProvider>
    );
}

Remembered layout ​

With storage on the provider, the view remembers per table the column widths, hidden and pinned columns, page size, filters and sorts, under database:table:<connection id>:<schema>.<table>.

When a table is read only ​

Add row, Delete, editing and import are off, and their tooltips say why:

ReasonMessage
The connection has readOnly: true.This connection is read only.
The table is a view.A view cannot be edited.
The table has no primary key or usable unique key.This table has no primary key or unique key, so its rows cannot be told apart.

Filtering, sorting, export and the record view keep working, with read only fields.

tsx
import { TableView } from '@adecore/database';
import { ShopDatabase } from '../shared/database.tsx';
import { SHOP_READ_ONLY } from '../shared/shop.ts';

export default function TableViewReadOnlyDemo() {
    return (
        <ShopDatabase>
            <div className="flex h-80 w-full overflow-hidden rounded-lg border border-border bg-surface">
                <TableView connection={SHOP_READ_ONLY} schema="main" table="orders" className="min-w-0 flex-1" />
            </div>
        </ShopDatabase>
    );
}

Your own content in the toolbar ​

toolbarStart draws the app's content before the command field, such as a breadcrumb. Separators then split the bar into three groups: yours, the command field and the buttons.

tsx
<TableView connection={connection} schema="main" table="orders" toolbarStart={<Breadcrumb connection={connection} schema="main" />} />

Props ​

PropTypeDefault
connectionConnectionRequired. The connection the table is in.
schemastringRequired. The schema of the table, main in SQLite.
tablestringRequired. The table or view.
toolbarStartReactNodeThe app's own content at the start of the toolbar.
defaultWherestringA filter the view starts with, as typed after WHERE.
defaultOrderBystringA sort the view starts with, as typed after ORDER BY.
onDirtyChange(dirty: boolean) => voidWhether the view holds pending changes.
classNamestringIts size.
refRef<HTMLDivElement>

The props are TableViewProps. The view needs a DatabaseProvider above it. Table views on one connection share its default session, outside any console transaction.

Licenses and third-party notices are listed in each package.