Search the documentation

Type to search page titles, component names and descriptions.

    Data Display

    DataTable

    A server-rendered table whose columns are data.

    import { DataTable } from 'faifo-design'

    DataTable renders rows from a list of column definitions. The table stays semantic, is contained horizontally, and stacks into labelled rows on a narrow width. It shows its own empty and loading states.

    #When to use

    • Use it for a read-only collection rendered on the server.
    • For selection, bulk actions, grouping and paging managed in the browser, use FaifoTable.
    • For entering lines, use FaifoGrid.

    #Examples

    Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.

    #Data table

    Columns are data; rows remain semantic and horizontally contained.

    Recent sales orders

    OrderCustomerTotalState
    Ready to invoice2
    SO-1042Công ty Ánh Dương18.450.000 ₫Ready
    SO-1041Khách sạn Mùa Hạ6.800.000 ₫Review
    2 shown in Ready
    Needs decision1
    SO-1039Nguyễn Minh Châu2.150.000 ₫Blocked
    Show codeHide code
    import { Badge, DataTable, LinkButton } from 'faifo-design'
    
    type OrderRow = {
      id: string
      customer: string
      total: string
      state: 'Ready' | 'Review' | 'Blocked'
    }
    
    const orders: OrderRow[] = [
      { id: 'SO-1042', customer: 'Công ty Ánh Dương', total: '18.450.000 ₫', state: 'Ready' },
      { id: 'SO-1041', customer: 'Khách sạn Mùa Hạ', total: '6.800.000 ₫', state: 'Review' },
      { id: 'SO-1039', customer: 'Nguyễn Minh Châu', total: '2.150.000 ₫', state: 'Blocked' },
    ]
    
    const toneOf = (state: OrderRow['state']) =>
      state === 'Ready' ? ('positive' as const) : state === 'Review' ? ('warning' as const) : ('danger' as const)
    
    export const Example = () => (
      <DataTable
        title="Recent sales orders"
        actions={<LinkButton label="View all orders" href="#app-shell" variant="tertiary" />}
        rows={[] as OrderRow[]}
        id={(row) => row.id}
        rowHref={(row) => `#${row.id}`}
        responsive="stack"
        gutter="compact"
        selection={{ selectedIds: ['SO-1042'] }}
        groups={[
          {
            id: 'ready',
            label: 'Ready to invoice',
            count: 2,
            href: '#data-table',
            rows: orders.slice(0, 2),
            pager: { label: '2 shown in Ready', nextHref: '#data-table' },
          },
          {
            id: 'blocked',
            label: 'Needs decision',
            count: 1,
            rows: orders.slice(2),
          },
        ]}
        columns={[
          {
            key: 'id',
            label: 'Order',
            cell: (row) => row.id,
            priority: 'primary',
            kind: 'identifier',
            sort: { href: '#data-table', direction: 'descending' },
          },
          { key: 'customer', label: 'Customer', cell: (row) => row.customer },
          { key: 'total', label: 'Total', cell: (row) => row.total, align: 'end', kind: 'currency' },
          {
            key: 'state',
            label: 'State',
            cell: (row) => <Badge label={row.state} tone={toneOf(row.state)} />,
            kind: 'status',
          },
        ]}
      />
    )

    #Retained results during a read

    The island owns request timing. ListPage announces busy state and dims retained results with the pending opacity token.

    Invoices

    Retained results

    OrderCustomerTotalState
    SO-1042Công ty Ánh Dương18.450.000 ₫Ready
    SO-1041Khách sạn Mùa Hạ6.800.000 ₫Review
    SO-1039Nguyễn Minh Châu2.150.000 ₫Blocked
    Show codeHide code
    import { TemplateResult } from '@ketvietlab/ketjs-view'
    import { Badge, DataTable, ListPage } from 'faifo-design'
    
    type OrderRow = {
      id: string
      customer: string
      total: string
      state: 'Ready' | 'Review' | 'Blocked'
    }
    
    const orders: OrderRow[] = [
      { id: 'SO-1042', customer: 'Công ty Ánh Dương', total: '18.450.000 ₫', state: 'Ready' },
      { id: 'SO-1041', customer: 'Khách sạn Mùa Hạ', total: '6.800.000 ₫', state: 'Review' },
      { id: 'SO-1039', customer: 'Nguyễn Minh Châu', total: '2.150.000 ₫', state: 'Blocked' },
    ]
    
    const toneOf = (state: OrderRow['state']) =>
      state === 'Ready' ? ('positive' as const) : state === 'Review' ? ('warning' as const) : ('danger' as const)
    
    const OrdersTable = (props: { grouped?: boolean; title?: string } = {}): TemplateResult => (
      <DataTable
        title={props.title}
        rows={props.grouped ? ([] as OrderRow[]) : orders}
        id={(row) => row.id}
        rowHref={(row) => `#${row.id}`}
        responsive="stack"
        selection={{ selectedIds: ['SO-1042'] }}
        groups={
          props.grouped
            ? [
                {
                  id: 'ready',
                  label: 'Ready to invoice',
                  count: 2,
                  rows: orders.slice(0, 2),
                  pager: { label: '2 shown in Ready', nextHref: '#data-table' },
                },
                {
                  id: 'blocked',
                  label: 'Needs decision',
                  count: 1,
                  rows: orders.slice(2),
                },
              ]
            : undefined
        }
        columns={[
          {
            key: 'id',
            label: 'Order',
            cell: (row) => row.id,
            priority: 'primary',
            kind: 'identifier',
            sort: { href: '#data-table', direction: 'descending' },
          },
          { key: 'customer', label: 'Customer', cell: (row) => row.customer },
          { key: 'total', label: 'Total', cell: (row) => row.total, align: 'end', kind: 'currency' },
          {
            key: 'state',
            label: 'State',
            cell: (row) => <Badge label={row.state} tone={toneOf(row.state)} />,
            kind: 'status',
          },
        ]}
      />
    )
    
    export const Example = () => (
      <ListPage title="Invoices" busy dimmed body={<OrdersTable title="Retained results" />} />
    )

    #API

    Generated from the package source. A property without a description has none in the source yet.

    #DataTableComponent

    PropertyDescriptionTypeDefault
    titleA shared surface contains the heading and an unframed table viewport.string–
    descriptionOne line under the title, such as how the rows relate; shown only with title.string | null–
    actions–JSXChild–
    columnsrequired–readonly Column<Row>[]–
    rowsrequired–readonly Row[]–
    idrequired–(row: Row) => string–
    caption–string | null–
    labelNames the table for assistive technology without a visible caption, for a table whose Section or Surface heading already says what it is.string | null–
    rowHref–(row: Row) => string–
    selected–(row: Row) => boolean–
    emptyTitle–string'No records'
    emptyMessage–string'There is nothing to show yet.'
    emptyActions–JSXChild–
    responsiveStack labelled cells on narrow screens, or retain horizontal scrolling.'scroll' | 'stack''scroll'
    gutterUse a denser gutter for high-volume operational lists.'default' | 'compact'–
    selection–TableSelection | null–
    groups–readonly TableGroup<Row>[]–
    shownColumns–readonly string[]–
    labels–DataTableLabels<Row>–

    #Types

    #Cell

    type Cell = JSXChild

    #Column

    PropertyDescriptionTypeDefault
    keyrequired–string–
    labelrequired–string–
    cellrequired–(row: Row) => Cell–
    align–'start' | 'end'–
    kindactions: a row's own commands. A stacked row shows them without the column's name.'text' | 'number' | 'currency' | 'date' | 'status' | 'identifier' | 'person' | 'media' | 'actions'–
    priority–'primary' | 'secondary' | 'tertiary'–
    width–'narrow' | 'medium' | 'wide'–
    hidden–boolean–
    optional–boolean–
    sort–{ href: string direction?: SortDirection | null label?: string } | null–

    #DataTableLabels

    PropertyDescriptionTypeDefault
    selectAll–string–
    selectRow–(row: Row, id: string) => string–
    sortedAscending–string–
    sortedDescending–string–
    previousPage–string–
    nextPage–string–

    #DataTableProps

    The properties of DataTable, listed above.

    #SortDirection

    type SortDirection = 'ascending' | 'descending'

    #TableGroup

    PropertyDescriptionTypeDefault
    idrequired–string–
    labelrequired–JSXChild–
    count–number–
    href–string | null–
    rows–readonly Row[]–
    children–readonly TableGroup<Row>[]–
    pager–TablePager | null–

    #TablePager

    PropertyDescriptionTypeDefault
    labelrequired–string–
    previousHref–string | null–
    nextHref–string | null–

    #TableSelection

    PropertyDescriptionTypeDefault
    formAssociates row checkboxes with an external bulk-action form.string–
    name–string–
    selectAllName–string–
    selectedIds–readonly string[]–
    disabled–boolean–

    #Hooks

    The data-ui values these components render. Select them in tests and behaviour; their look belongs to the design system. See Contract.

    • table-scroll
    • table
    • table-caption
    • select-col
    • select-all
    • col
    • sort-link
    • sort-icon
    • row
    • group-row
    • group-cell
    • group-link
    • group-indent
    • group-count
    • group-pager
    • group-pager-actions
    • cell
    • select-cell
    • row-select
    • row-link