QueryTable
Runs the real component in your browser.
The foundation of records pages: a query results table with paging, column settings, row actions and a selection bar; the header stays put while loading and on empty results.
Status: stable · Components: QueryTable, Pager, ColumnSettingsButton, RowActionsCell, SelectionBar
Import
Section titled “Import”import { QueryTable, Pager, ColumnSettingsButton, RowActionsCell, SelectionBar } from 'nacre'Minimal usage: column definitions plus row data. Numeric columns are right-aligned and tabular.
import { View, token } from 'nsh'import { QueryTable } from 'nacre'import type { QueryColumn } from 'nacre'
type Ticket = { id: string; customer: string; status: string; minutes: number }
const rows = (): Ticket[] => Array.from({ length: 23 }, (_, i) => ({ id: `T${String(i + 1).padStart(3, '0')}`, customer: `$Customer ${i + 1}`, status: i % 3 === 0 ? 'Closed' : 'In progress', minutes: (i * 7) % 60, }))
const columns = (): QueryColumn<Ticket>[] => [ { key: 'id', title: 'Ticket no.', width: 96 }, { key: 'customer', title: 'Customer', width: 140 }, { key: 'status', title: 'Status', width: 96 }, { key: 'minutes', title: 'Duration (min)', width: 96, numeric: true },]
export function TableUsage() { return ( <View class="rounded-xl border border-border overflow-hidden" style={{ height: 6 * Number(token('control-h-lg')) + 6 }}> <QueryTable columns={columns()} rows={rows().slice(0, 5)} testID="doc-table-usage" /> </View> )}Examples
Section titled “Examples”Row actions
Section titled “Row actions”rowActions gives each row’s actions; inlineActions decides how many show directly, and the rest go into the “More” menu at the end of the row.
import { View, signal, token } from 'nsh'import { QueryTable, createTableState } from 'nacre'import type { QueryColumn } from 'nacre'
type Ticket = { id: string; customer: string; status: string; minutes: number }
const rows = (): Ticket[] => Array.from({ length: 23 }, (_, i) => ({ id: `T${String(i + 1).padStart(3, '0')}`, customer: `$Customer ${i + 1}`, status: i % 3 === 0 ? 'Closed' : 'In progress', minutes: (i * 7) % 60, }))
const columns = (): QueryColumn<Ticket>[] => [ { key: 'id', title: 'Ticket no.', width: 96 }, { key: 'customer', title: 'Customer', width: 140 }, { key: 'status', title: 'Status', width: 96 }, { key: 'minutes', title: 'Duration (min)', width: 96, numeric: true },]
export function TableRowActions() { const last = signal('') const data = rows() return ( <View class="rounded-xl border border-border overflow-hidden" style={{ height: 6 * Number(token('control-h-lg')) + 6 }}> <QueryTable columns={columns()} rows={data.slice(0, 5)} state={createTableState()} rowActions={(row) => [ { key: 'detail', label: 'Details', run: () => last.set(`$Details ${row.id}`) }, { key: 'assign', label: 'Assign', run: () => last.set(`$Assign ${row.id}`) }, { key: 'close', label: 'Finish', run: () => last.set(`$Finish ${row.id}`) }, ]} inlineActions={1} testID="doc-table-actions" /> </View> )}Paging and empty results
Section titled “Paging and empty results”pager sits at the bottom; empty results offer “Clear filters” (onClearFilters).
import { View, signal } from 'nsh'import { QueryTable } from 'nacre'import type { QueryColumn } from 'nacre'
type Ticket = { id: string; customer: string; status: string; minutes: number }
const rows = (): Ticket[] => Array.from({ length: 23 }, (_, i) => ({ id: `T${String(i + 1).padStart(3, '0')}`, customer: `$Customer ${i + 1}`, status: i % 3 === 0 ? 'Closed' : 'In progress', minutes: (i * 7) % 60, }))
const columns = (): QueryColumn<Ticket>[] => [ { key: 'id', title: 'Ticket no.', width: 96 }, { key: 'customer', title: 'Customer', width: 140 }, { key: 'status', title: 'Status', width: 96 }, { key: 'minutes', title: 'Duration (min)', width: 96, numeric: true },]
export function TablePaged() { const page = signal(1) const pageSize = 10 const data = rows() return ( <View class="h-[420px] rounded-xl border border-border overflow-hidden"> <QueryTable columns={columns()} rows={data.slice((page() - 1) * pageSize, page() * pageSize)} pager={{ page: page(), pageSize, total: data.length, onPage: (next) => page.set(next) }} testID="doc-table-paged" /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab / Shift+Tab | Move forward or backward through header controls, the table body and row controls. Tabbing into the body makes the first row current (or returns to the row you left). |
| ↑ ↓ | Move the current row. While the table has focus the current row has a soft brand fill, turning neutral gray once focus leaves; no outlines or focus frame. |
| Return | Open the current row (onOpen) |
| Space | Toggle the focused checkbox or activate a sort or paging button |
Accessibility
Section titled “Accessibility”- The table name includes the number of records on this page and the number of data columns.
- Sort buttons announce their column and sort direction and retain focus after activation.
- Pagination identifies the current page. The row menu button is named “More actions”.
Do / Don’t
Section titled “Do / Don’t”Do
- Mark numeric columns numeric (right-aligned, tabular)
- Keep the “Actions” column always visible
- Offer “Clear filters” on empty results
Don’t
- Flash the whole table white while loading (show loading; keep the header still)
- Put long text in cells (lines is at most 3)
Property descriptions follow the Chinese source comments.
QueryTable
Section titled “QueryTable”| Prop | Type | Default | Description |
|---|---|---|---|
columns * |
QueryColumn<Row>[] |
— | |
rows * |
Row[] |
— | |
state |
QueryTableState |
— | |
loading |
boolean |
— | |
density |
'default' | 'dense' |
— | default 表头 40 / 行 36;dense 32 / 32 |
arrowKeys |
'focus' | 'page' |
— | ↑↓ 选行、⏎ 打开什么时候生效:focus(默认)只在焦点在表格里时,不抢页面上别的控件的方向键; page 整页都归表格(记录页:表格是页面的主体,进页就能 ↑↓)。整页键盘模型第二期接上区域后,page 改为「表格所在区域有焦点」 |
verticalScrollbar |
boolean |
— | 竖向滚动条,默认显示;所在分栏做宽度动画时关掉,免得它跟着表格右缘横扫过去 |
sort |
QuerySort | null |
— | |
onSortChange |
(sort: QuerySort | null) => void |
— | |
onColumnMove |
(order: string[]) => void |
— | |
onColumnResize |
(key: string, width: number) => void |
— | 给了就能拖列右缘调宽(拖动中每步回调);列宽由调用方存、再经 columns[].width 传回(受控) |
onOpen |
(row: Row, index: number) => void |
— | |
opened |
number | null |
— | 打开详情的那一行:整行 selection 底常亮(同 macOS 邮件里打开着的那封,与键盘当前行、勾选区分);非空时 ↑↓ 换行也换详情 |
rowActions |
(row: Row, index: number) => RowAction[] |
— | 「操作」列,固定在最右 |
inlineActions |
number |
— | |
selection |
{ actions: (rows: Row[]) => RowAction[]; canSelect?: (row: Row) => boolean } |
— | 给了就有勾选列与底部批量条 |
onRowContextMenu |
(row: Row, index: number, at: MenuPoint) => void |
— | |
onHeaderContextMenu |
(key: string, at: MenuPoint) => void |
— | |
pager |
PagerProps |
— | |
empty |
JSX.Element |
— | 整个换掉空态;一般不用,给 emptyTitle / emptyDescription 就够 |
emptyTitle |
string |
— | 本来没有数据时的空态标题(「没有委托订单」),默认「暂无数据」 |
emptyDescription |
string |
— | 本来没有数据时标题下的一句说明 |
onClearFilters |
() => void |
— | 有筛选条件时给:空结果换成「当前筛选无结果」+ 说明 +「清空筛选」按钮,和本来没有数据分开 |
sizing |
'fill' | 'content' |
— | fill(默认):撑满父级,行多了表内竖向滚动(查询页)。 content:高度跟内容走(表头 + 各行,空表是紧凑的空态,加分页条),嵌在卡片、抽屉里由外层滚动;横向溢出时底部再让出滚动条的高度, 覆盖式滚动条不压最后一行 |
borderTop |
boolean |
— | 顶部 1pt 分隔线,默认有(接在筛选栏下面);放在自带描边的卡片里时关掉 |
keyboard |
boolean |
— | 收不收全局的 ↑↓⏎(默认收):页面被保活隐藏、或表格嵌在别的面板里时关掉,免得抢走前台的按键 |
testID |
string |
'record' |
testID 前缀,默认 record |
* required
| Prop | Type | Default | Description |
|---|---|---|---|
page * |
number |
— | |
pageSize * |
number |
— | |
pageSizes |
readonly number[] |
— | |
total |
number |
0 |
不知道总数时(模板 ignore_count)不给,用 hasNext 推页数 |
hasNext |
boolean |
— | |
onPage * |
(page: number) => void |
— | |
onPageSize |
(size: number) => void |
— | |
compact |
boolean |
— | 只有上一页 / 下一页(右栏这类窄处) |
leading |
JSX.Element |
— | 底栏左侧(勾选后的批量条);不给时左侧显示数据更新时间 |
updatedAt |
number | null |
0 |
上次加载成功的时间(毫秒):「更新于 HH:mm:ss」 |
updating |
boolean |
— | 正在重查:「数据更新中…」 |
testID |
string |
'record' |
* required
ColumnSettingsButton
Section titled “ColumnSettingsButton”| Prop | Type | Default | Description |
|---|---|---|---|
columns * |
readonly ColumnInfo[] |
— | |
value * |
ColumnSettings |
— | |
locked |
readonly string[] |
— | |
onChange * |
(next: ColumnSettings) => void |
— | |
onReset * |
() => void |
— | |
density |
Signal<TableDensity> |
— | 给了就在脚部上方出「行高」切换:标准(default)/ 紧凑(dense),持久化由调用方做 |
onDensity |
(next: TableDensity) => void |
— |
* required
RowActionsCell
Section titled “RowActionsCell”| Prop | Type | Default | Description |
|---|---|---|---|
actions * |
RowAction[] |
— | |
inline |
number |
— | |
testID * |
string |
— |
* required
SelectionBar
Section titled “SelectionBar”| Prop | Type | Default | Description |
|---|---|---|---|
actions * |
RowAction[] |
— | |
count * |
number |
— | |
onClear * |
() => void |
— | |
testID |
string |
'record-batch' |
* required