Data grid
DataGrid. It is copied into your app’s ui/ by qatjs add grid: the code is yours to edit.
Example
| Order | Customer | Status | Total | |
|---|---|---|---|---|
| 10482 | Customer 1 | Delivered | 0.50 ₼ | |
| 10481 | Customer 2 | On the way | 37.50 ₼ | |
| 10480 | Customer 3 | Failed | 74.50 ₼ | |
| 10479 | Customer 4 | New | 111.50 ₼ | |
| 10478 | Customer 5 | Delivered | 148.50 ₼ | |
| 10477 | Customer 6 | On the way | 185.50 ₼ | |
| 10476 | Customer 7 | Failed | 222.50 ₼ | |
| 10475 | Customer 8 | New | 259.50 ₼ | |
| 10474 | Customer 9 | Delivered | 296.50 ₼ | |
| 10473 | Customer 10 | On the way | 333.50 ₼ | |
| 10472 | Customer 11 | Failed | 370.50 ₼ | |
| 10471 | Customer 12 | New | 7.50 ₼ | |
| 10470 | Customer 13 | Delivered | 44.50 ₼ |
0 selected, opened none
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 stateAdd it
npx qatjs add gridDataGrid
As a custom element: <ui-data-grid>.
| Prop | Type | Attribute |
|---|---|---|
label | string | yes |
columns | GridColumn<T>[] | property only |
rows | T[] | property only |
rowKey | (row: T) => string | property only |
height | number | yes |
density | 'comfortable' | 'compact' | yes |
selectable | boolean | yes |
selected | string[] | property only |
sort | GridSort | property only |
manualSort | boolean | yes |
empty | QatNode | property only |
use | GridOption<T>[] | property only |
| Event | Detail |
|---|---|
on:update:selected | CustomEvent<string[]> |
on:update:sort | CustomEvent<GridSort> |
on:activate | CustomEvent<string> |
on:resize | CustomEvent<[string, number]> |
Keys
| Key | Does |
|---|---|
| ← → ↑ ↓ | cell to cell |
| Home, End | the row’s ends |
| Ctrl+Home, Ctrl+End | the grid’s ends |
| PageUp, PageDown | a screenful |
| Enter | sort (header), activate (row) |
| Space | select the row |
| Shift+← → | resize the column (header) |