Tally UI

ProductTable

ProductTable renders virtualised product rows with default trait or custom columns, sortable headers, and optional search and filter slots.

Import

import { ProductTable, defaultProductColumns, useDefaultProductColumns } from '@tallyui/components';
import type { ProductTableProps, ProductTableColumn } from '@tallyui/components';
import type { ProductSort } from '@tallyui/pos';

Usage

<ProductTable
  items={products}
  onSelect={handleSelect}
  searchSlot={<SearchInput value={query} onChangeText={setQuery} />}
  emptyState={<Text>No products</Text>}
/>

Under a ConnectorProvider, the default columns are Name, SKU, Barcode, Price, Stock and Category. Prices use the resolved sale price or the lowest variant price. Stock uses the provider's reconciled overlay. Unsellable products are hidden by default.

Press a sortable header to cycle through ascending, descending and no sort. The header stays above the virtualised rows. Supply sort and onSortChange to control sorting; sort={null} means no sort. With sortItems={false}, the header reports sort changes while rows retain the supplied order.

Props

PropTypeDefaultDescription
itemsany[]requiredProduct documents
columnsProductTableColumn[]trait columnsCustom columns; defaults to none without a provider
sortProductSort | nulluncontrolledControlled sort field and direction
defaultSortProductSort | nullnullInitial uncontrolled sort
onSortChange(sort: ProductSort | null) => void—Called on each sortable header press
sortItemsbooleantrueSort rows locally; false leaves ordering to the app
onSelect(doc: any) => void—Makes rows pressable
searchSlotReactNode—Content above the filter slot
filterSlotReactNode—Content above the table
emptyStateReactNode—Replaces the entire table when no visible items remain
loadingbooleanfalseWith no items, draws the header and skeleton rows (one line placeholder per cell) instead of emptyState, as WCPOS v2
showUnsellablebooleanfalseInclude products the channel does not sell
currencySymbolstring—Passed to the default price column
showThumbnailbooleanfalseLeads each row with the product's thumbnail, as v2's image column (an initial tile when there is no image); needs a ConnectorProvider
showAddButtonbooleanfalseEnds each row with v2's add control, which calls onSelect(item) as a row press does: a + labelled “Add to cart”, or a > labelled “Variations” for a product with more than one variant; needs onSelect
cartQuantity(doc: any) => numberno countHow many of the product the cart holds; in the add column a count above 0 shows in place of the +, labelled “In cart: N”, and pressing it calls onSelect
isExpanded(doc: any) => boolean—Whether a row's expanded block shows; pass a new function when it changes
onToggleExpand(doc: any) => void—With renderExpanded and showThumbnail (or variationsButton), a product with more than one variant has its thumbnail toggle its block (a “Show variations” button with aria-expanded); a press calls this, not onSelect
renderExpanded(doc: any) => ReactNode—Drawn under an expanded row, indented by the thumbnail column when it shows
variationsButtonbooleanfalsev2's “count variations” button, with a chevron and aria-expanded, under the first cell of a product with more than one variant; a press calls onToggleExpand, never onSelect, and the row expands without showThumbnail; needs onToggleExpand and renderExpanded
classNamestring—Override container styles

Other ViewProps are forwarded to the container.

Columns

Each column has a stable id, a header label and a render(doc) function. Optional flex controls its width weight (default 1); sortValue(doc) enables header sorting. Missing values sort last in either direction.

align ('left', 'center' or 'right') places the head and the cells together; the default Price column is right-aligned. hideHeader draws no head label while header stays the head's accessible name, for an image column.

Heads are one line and 36 px tall; cells are padded px-3 py-1.5, WCPOS v2's table.

defaultProductColumns(traits, context?, { currencySymbol }?) builds the six default columns. useDefaultProductColumns({ currencySymbol }?) memoises them from the provider and requires a ConnectorProvider.

Custom columns can render without a provider:

<ProductTable
  items={products}
  columns={[{
    id: 'name',
    header: 'Name',
    render: (doc) => <Text>{doc.name}</Text>,
    sortValue: (doc) => doc.name,
  }]}
/>