qat

Data grid

DataGrid. It is copied into your app’s ui/ by qatjs add grid: the code is yours to edit.

Example

OrderCustomerStatusTotal
10482Customer 1Delivered0.50 ₼
10481Customer 2On the way37.50 ₼
10480Customer 3Failed74.50 ₼
10479Customer 4New111.50 ₼
10478Customer 5Delivered148.50 ₼
10477Customer 6On the way185.50 ₼
10476Customer 7Failed222.50 ₼
10475Customer 8New259.50 ₼
10474Customer 9Delivered296.50 ₼
10473Customer 10On the way333.50 ₼
10472Customer 11Failed370.50 ₼
10471Customer 12New7.50 ₼
10470Customer 13Delivered44.50 ₼

0 selected, opened none

Example.qx42 lines, 2 reactive namesOpen in the playground
import DataGrid from './ui/grid/grid.qx'

const statuses = ['Delivered', 'On the way', 'Failed', 'New']
const orders = Array.from({ length: 1000 }, (_, i) => ({
  id: String(10482 - i),
  name: `Customer ${i + 1}`,
  status: statuses[i % 4],
  total: ((i * 37) % 400) + 0.5,
}))

export default function Example() {
  let picked = state<string[]>([])
  let opened = state('')
  return (
    <DataGrid
      label="All orders"
      columns={[
        { key: 'id', label: 'Order', mono: true, width: 110 },
        { key: 'name', label: 'Customer', sortable: true, width: 220 },
        { key: 'status', label: 'Status', width: 140 },
        {
          key: 'total',
          label: 'Total',
          align: 'end',
          mono: true,
          sortable: true,
          width: 120,
          cell: (o) => o.total.toFixed(2) + ' ₼',
        },
      ]}
      rows={orders}
      rowKey={(o) => o.id}
      height={320}
      selectable
      bind:selected={picked}
      on:activate={(k) => (opened = k)}
    />
    <p>
      {picked.length} selected, opened {opened || 'none'}
    </p>
  )
}
picked stateopened state

Add it

shell1 line
npx qatjs add grid

DataGrid

As a custom element: <ui-data-grid>.

DataGrid: props
PropTypeAttribute
labelstringyes
columnsGridColumn<T>[]property only
rowsT[]property only
rowKey(row: T) => stringproperty only
heightnumberyes
density'comfortable' | 'compact'yes
selectablebooleanyes
selectedstring[]property only
sortGridSortproperty only
manualSortbooleanyes
emptyQatNodeproperty only
useGridOption<T>[]property only
DataGrid: events
EventDetail
on:update:selectedCustomEvent<string[]>
on:update:sortCustomEvent<GridSort>
on:activateCustomEvent<string>
on:resizeCustomEvent<[string, number]>

Keys

KeyDoes
← → ↑ ↓cell to cell
Home, Endthe row’s ends
Ctrl+Home, Ctrl+Endthe grid’s ends
PageUp, PageDowna screenful
Entersort (header), activate (row)
Spaceselect the row
Shift+← →resize the column (header)