Tally UI

ProductTable

Virtualised product table with default trait columns and header sort

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
showUnsellablebooleanfalseInclude products the channel does not sell
currencySymbolstring—Passed to the default price column
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.

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,
  }]}
/>