qat

DataGrid options

qat/ui's DataGrid (qatjs add grid) is a headless core: rows on virtual(), sorting by one column, selection, resizing, the WAI-APG grid keys. Everything else is an option, a module of its own, put in use and paid for only when used:

.qx24 linesOpen in the playground
// orders.qx
import DataGrid from './ui/grid/grid.qx'
import { reorder } from './ui/grid/reorder.ts'
import { pin } from './ui/grid/pin.ts'
import { group } from './ui/grid/group.ts'
import { csv } from './ui/grid/csv.ts'
import { currency } from './ui/grid/format.ts'

export default function Orders({ orders }) {
  return (
    <DataGrid
      label="Orders"
      rows={orders}
      rowKey={(o) => o.id}
      columns={[
        { key: 'id', label: 'Order', width: 110 },
        { key: 'name', label: 'Customer', sortable: true },
        { key: 'status', label: 'Status' },
        { key: 'total', label: 'Total', align: 'end', format: currency('AZN') },
      ]}
      use={[reorder(), pin({ left: ['id'] }), group({ by: 'status', aggregate: { total: 'sum' } }), csv()]}
    />
  )
}
Option What it adds Size (gzip)
reorder() a header's grip, dragged (9b's on:drag); Alt+Shift+←/→ on a header cell 633 B
pin({ left, right }) columns stuck to an edge while the grid scrolls sideways, a shadow at the edge 314 B
visibility({ hidden }) a Columns menu, a checkbox per column; hidden may be a persisted store field 324 B
group({ by, aggregate }) a row per group (open or closed) with sum, count, avg, min, max under their columns 834 B
facets({ columns }) a filter menu in those headers: each value with its count 801 B
multiSort() Shift+click adds a column to the sort; badges show the priority 667 B
density() a Compact rows toggle (44 px rows or 36) 336 B
format.ts a column's format: number, currency, percent, date, in the page's locale 303 B
csv({ filename }) an Export CSV button: the view as shown, made in the browser 602 B

The core is 3.0 kB of its 5 kB. An option's size counts neither qat nor the Menu it mounts.

Large tables. group and facets run on 10b's delta mode (large collections). Over a deep store (state([...])), a row that changes moves one count, one sum, one group: a grouped 100k table does not regroup itself. The rows drawn are the window's; a change rewrites only the cells whose values changed.

Persisting what the user chose: give an option a signal the app keeps. For example a store({ persist: 'local' }) field: visibility({ hidden: prefs.hidden }) in a .ts or .js module, where prefs.hidden is the field's signal. In .qx, prefs.hidden reads the value, so take the signal out first: const { hidden } = prefs, then visibility({ hidden }).

CSV. The export writes the columns as shown and the rows as filtered and sorted, each value as its column formats it. A group's own rows are left out. A value a spreadsheet would run as a formula (=, +, -, @) is written as text, except a plain number (-12.50, a refund), which stays a number the spreadsheet sums. Nothing is sent anywhere.

Against TanStack Table

TanStack Table 9.3.1 (@tanstack/table-core, its stock features as its package lists them) is headless: it computes, and the app draws. DataGrid draws, with the keys and the ARIA, so "yes" here means drawn and working.

Feature Qat DataGrid TanStack Table 9.3.1
sorting yes yes
multi-sort, with priority yes (multiSort, badges) yes (no badges: the app draws them)
column ordering yes (reorder: drag and keyboard) yes (state only: the app draws the drag)
column pinning yes (pin, sticky, edge shadow) yes (state only)
column visibility yes (visibility, a menu, persistable) yes (state only)
column sizing and resizing yes (core: drag a header's edge, Shift+←/→) yes
grouping yes (group, rows of their own, open and closed) yes
aggregation yes: sum, count, avg, min, max yes, also median, extent, unique, first, last
faceting (values with counts) yes (facets, in delta mode) yes (row models: the app draws them)
column filtering yes (facets: by value) yes (any filter function)
global filtering no: the app filters rows before the grid (a derived), which is one line and keeps the filter its own yes
row selection yes (core) yes
row expanding (sub-rows) different: a group's rows open and close; nested sub-rows are not built yes
row pinning no: not asked of qat/ui yet; a pinned row is a row above the grid yes
pagination different: the grid virtualizes (100k rows in the page); paging is the data's (@qatjs/load/pages) yes
cell selection no: the grid's cell is the keyboard's focus (one active cell), not a range; a range is a later item yes
cell spanning no: the rows are a recycled pool of one shape; a group's row is the one that differs yes
virtualization yes (core: virtual()) separate (TanStack Virtual)
density yes (density) different: the app's CSS
formatting in a locale yes (format.ts, follows the locale) different: the app's cell renderer
CSV export yes (csv) no
keyboard (WAI-APG grid) and ARIA yes (core) different: the app's