Components

Table

Lightweight data table with sorting, striped rows, grouping, and built-in pagination.

iOSAndroid
Preview Table on your device

Scan with Expo Go

Download Expo Go, then scan the QR code to preview native components.

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-table

Usage

import { Table } from '@/components/docyrus-native/table';

type Product = { id: string; name: string; price: number };

const data: Product[] = [
  { id: '1', name: 'Widget', price: 9.99 },
  { id: '2', name: 'Gadget', price: 19.99 },
];

<Table
  data={data}
  columns={[
    { key: 'name', title: 'Name', sortable: true },
    { key: 'price', title: 'Price', align: 'right' },
  ]}
  keyExtractor={(item) => item.id}
/>

Striped & Bordered

<Table data={data} columns={columns} keyExtractor={(item) => item.id} striped bordered />

With Sorting

const [sortKey, setSortKey] = useState<string | undefined>();
const [sortDir, setSortDir] = useState<'asc' | 'desc' | null>(null);

<Table
  data={data}
  columns={columns}
  keyExtractor={(item) => item.id}
  sortKey={sortKey}
  sortDirection={sortDir ?? undefined}
  onSort={(key, dir) => { setSortKey(key); setSortDir(dir); }}
/>

With Pagination

<Table
  data={data}
  columns={columns}
  keyExtractor={(item) => item.id}
  currentPage={page}
  totalPages={5}
  totalItems={50}
  pageSize={10}
  onPageChange={setPage}
/>

API Reference

PropTypeDefaultDescription
dataT[]—Array of data items to display
columnsTableColumn<T>[]—Column definitions
keyExtractor(item: T) => string—Function to extract unique key per row
sortKeystring—Currently sorted column key
sortDirection'asc' | 'desc'—Current sort direction
onSort(key: string, direction: 'asc' | 'desc' | null) => void—Sort change callback
stripedbooleanfalseAlternate row background colors
borderedbooleanfalseShow column border lines
size'sm' | 'md' | 'lg''md'Table cell padding and font size
groupBystring—Data key to group rows by
groupHeaderRender(groupKey: string, items: T[]) => ReactNode—Custom group header renderer
emptyMessagestring'No data available'Message when data is empty
loadingbooleanfalseShow loading state
currentPagenumber—Current page for pagination
totalPagesnumber—Total pages for pagination
totalItemsnumber—Total item count for pagination info
pageSizenumber—Items per page for pagination info
onPageChange(page: number) => void—Page change callback
classNamestring—Additional CSS classes

TableColumn<T>

PropTypeDefaultDescription
keystring—Data field key
titlestring—Column header text
widthnumber120Column width in pixels
sortablebooleanfalseWhether column is sortable
align'left' | 'center' | 'right''left'Text alignment
render(value: unknown, item: T, index: number) => ReactNode—Custom cell renderer

Translation Keys

Built-in copy is read through useUiTranslation() — provide these keys via <UiTranslationProvider>. Without a provider the English fallback is shown.

KeyEnglish fallbackUsed for
ui.table.loadingLoading...Loading row
ui.table.emptyNo data availableEmpty text (emptyMessage prop wins)

Type Exports

TypeDescription
TableProps<T>Props for Table component
TableColumn<T>Column definition type
TableSize'sm' | 'md' | 'lg'

On this page