Tally UI

OrderTable

WCPOS v2's orders table, with host columns, a sortable header and an Open order chevron

Import

import { OrderTable, type OrderTableColumn } from '@tallyui/components';

Usage

const columns: OrderTableColumn<Order>[] = [
  { id: 'number', header: 'Order Number', render: (o) => <Text>{o.reference}</Text>, sortValue: (o) => o.reference },
  { id: 'date_created', header: 'Date Created', render: (o) => <Text>{o.placedAt}</Text>, sortValue: (o) => Date.parse(o.placedAt) },
  { id: 'total', header: 'Total', align: 'right', render: (o) => <Text>{o.total}</Text>, sortValue: (o) => o.totalMinor },
];

<OrderTable items={orders} columns={columns} getRowId={(o) => o.id} onOpen={(o) => openOrder(o.id)} />

The table is generic over the host's row type. Every cell comes from a column's render, so a host can feed store orders, local sales or a union of both.

Sorting

A column with sortValue gets a sort button in its header, named "Sort by" and the header text. As in WCPOS v2, pressing the sorted column flips it between ascending and descending, pressing another column sorts it ascending, and the header never returns to no sort. The default sort is Date Created, newest first (the column with id date_created).

  • Client sort (the default): the table orders items by the active column's sortValue. Numbers compare as numbers, text compares naturally (so #9 comes before #10), a missing value goes last in both directions and ties keep their given order.
  • Server sort (sortItems={false}): for a paged list sorted by the server. The table keeps items in the order given and the header still shows the sort. Pass sort and onSortChange, and refetch from the first page when the sort changes.

Leave sort undefined for the table to keep its own sort, starting from defaultSort.

As in WCPOS v2's orders list, dayOf puts a day heading above each run of consecutive orders from one day while the table is sorted by dayColumn, in either direction; under any other sort there are no headings. The host keys and labels the day, so it decides the time zone. loading shows skeleton rows until the first items arrive.

Keyboard

On the web, when onOpen is given, the table takes the keyboard as WCPOS v2's orders list does. With the list focused, the up and down arrows move between orders, skipping day headings, and Enter opens the focused order. Enter on a control inside a row, such as the "Open order" chevron or a host chip, does only what that control does. The focused row's outline shows after a key move only, not after a click. Without onOpen, and on native, the rows take no keys.

Props

PropTypeDefaultDescription
itemsreadonly Row[]requiredThe rows
columnsOrderTableColumn<Row>[]requiredid, header, render, and optionally align, flex, width and sortValue
getRowId(row) => stringrequiredThe row's key, also used in its test ids
sortOrderTableSort—Controlled sort when defined
defaultSortOrderTableSortDate Created, descendingThe first sort when uncontrolled
onSortChange(sort) => void—Called with the next sort on each header press
sortItemsbooleantruefalse keeps the host's order
onOpen(row) => void—Draws a trailing "Open order" chevron button per row
onEndReached() => void—Called near the end of the list, for the next page
footerReactNode—Drawn under the last row, e.g. a loading indicator
emptyStateReactNode—Shown under the header when there are no items
dayOf(row) => { key, label } | undefined—The row's day, keyed and labelled by the host; heads each day under the dayColumn sort
dayColumnstring'date_created'The column whose sort shows day headings
loadingboolean—With no items, draws skeleton rows instead of emptyState
testIDstring'order-table'Prefix of the table's test ids

Rows are not buttons: an order opens from its chevron. Phone layouts, where v2 swaps the table for a list of rows, stay with the host.

Store orders

useStoreOrderColumns returns WCPOS v2's orders columns for StoreOrder rows, so a host need not write the cells itself.

const columns = useStoreOrderColumns({ formatDate, onFilterStatus: setStatus, onFilterCustomer: setCustomer });

By default it returns the six columns in DEFAULT_STORE_ORDER_COLUMNS: status, number, customer, date_created, payment_method and total. Four more are hidden unless named in visible: date_paid, created_via, cashier and register. Columns always come back in v2's order, whatever the order of visible.

OptionDescription
formatDateFormats an ISO 8601 UTC time for the date cells; the host picks the time zone
onFilterStatusMakes each status a button that calls it with the platform's raw status word, such as on-hold
onFilterCustomerMakes each customer with an id a button that calls it with the order's customer id and name
registerLabel, cashierLabelName a register or cashier id; the id shows when they return nothing
visibleThe column ids to return
localeThe locale for the totals

As in v2, the status and customer chips filter the list and never open the order. A customer without a name shows their email, then "ID: " and their id; a guest (no id) shows "Guest" as plain text, where v2 makes it a chip too. Under the total, an order with refunds shows their sum on a second line, in red with a minus sign. Status sorts by the raw word and Total by the amount; a guest sorts last under Customer, as does an order with no payments under Payment Method.

Differences from v2: the default set leaves out Created Via and Cashier, which v2 shows; Customer sorts by the name shown rather than the customer id; Date Paid sorts, where v2's does not; Payment Method sorts by the joined titles rather than the method id; Created Via shows the platform's own word rather than v2's icon; and the column ids drop v2's _gmt and _id suffixes (customer, date_created, date_paid).