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
| Prop | Type | Default | Description |
|---|---|---|---|
items | any[] | required | Product documents |
columns | ProductTableColumn[] | trait columns | Custom columns; defaults to none without a provider |
sort | ProductSort | null | uncontrolled | Controlled sort field and direction |
defaultSort | ProductSort | null | null | Initial uncontrolled sort |
onSortChange | (sort: ProductSort | null) => void | — | Called on each sortable header press |
sortItems | boolean | true | Sort rows locally; false leaves ordering to the app |
onSelect | (doc: any) => void | — | Makes rows pressable |
searchSlot | ReactNode | — | Content above the filter slot |
filterSlot | ReactNode | — | Content above the table |
emptyState | ReactNode | — | Replaces the entire table when no visible items remain |
loading | boolean | false | With no items, draws the header and skeleton rows (one line placeholder per cell) instead of emptyState, as WCPOS v2 |
showUnsellable | boolean | false | Include products the channel does not sell |
currencySymbol | string | — | Passed to the default price column |
showThumbnail | boolean | false | Leads each row with the product's thumbnail, as v2's image column (an initial tile when there is no image); needs a ConnectorProvider |
showAddButton | boolean | false | Ends 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) => number | no count | How 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 |
variationsButton | boolean | false | v2'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 |
className | string | — | 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,
}]}
/>ProductGrid
ProductGrid renders products in a scrollable column layout with custom item rendering, search and filter slots, and an optional empty state.
productsScreenColumns
productsScreenColumns gives ProductTable the read columns of WCPOS v2's Products screen; image, product with its variation count, stock with a Manage switch, stock status, categories and price.