Table
Compound table primitive. Semantic <table> on web for full a11y; View flex-grid on native.
2.4 kBgzipped
At a glance
- Compound primitive:
Table,.Header,.Body,.Footer,.Row,.HeaderCell,.Cell,.Caption. - Web uses semantic
<table>/<thead>/<tbody>/<tfoot>/<tr>/<th>/<td>/<caption>for full screen-reader support. - Native renders a
ScrollView+Viewflex-grid (all columns equal-width in v1; variable widths are a v2 improvement). - Optional cosmetic flags:
striped,compact,bordered. - Interactive rows via
onPressonTable.Row. - For automatic column/data rendering with sort + pagination, see DataTable.
Basic usage
Striped rows
Pass striped to alternate row backgrounds:
Compact
Tighter cell padding for dense layouts:
Bordered
Draw a border around all cells:
Aligned columns
align works on both Table.Cell and Table.HeaderCell:
Accepted values: 'left' (default) | 'center' | 'right'.
Column span
Pass colSpan to merge cells:
On web this maps to the HTML colspan attribute. On native it is a visual hint only (the cell still occupies its flex slot).
Clickable rows
Pass onPress to Table.Row to make a row interactive:
On web the row gets a pointer cursor and a hover background. On native it wraps in a Pressable with an opacity feedback.
Native notes
- The root element is a
ScrollViewwithhorizontalenabled so wide tables can scroll on narrow screens. - All columns share equal
flex: 1in v1. Custom column widths are deferred to v2. stripedis not yet applied on native (rows have no index-aware background without a parent counter context); use a plain list with custombackgroundColoron alternating rows as a workaround.compactreducespaddingVerticalon all rows.borderedadds aborderWidth: 1around the outer container.
Accessibility
- Web: uses semantic table elements. Screen readers announce column headers via
<th>and can navigate by row/column. - Native: no explicit
accessibilityRoleis set on the grid container; individual cells are plainViews. For data-heavy native UIs where VoiceOver/TalkBack navigation matters, consider labelling cells manually viaaccessibilityLabel.
API
Table
| Prop | Type | Default | Description |
|---|---|---|---|
striped | boolean | false | Alternate row background tinting. |
compact | boolean | false | Reduce cell padding. |
bordered | boolean | false | Draw borders around cells. |
className | string | — | Web: extra CSS classes on the <table>. |
testID | string | — | Test identifier. |
Table.Row
| Prop | Type | Default | Description |
|---|---|---|---|
selected | boolean | false | Highlight row as selected. |
onPress | () => void | — | Makes the row pressable. |
className | string | — | Web only. |
testID | string | — | Test identifier. |
Table.Cell / Table.HeaderCell
| Prop | Type | Default | Description |
|---|---|---|---|
align | 'left' | 'center' | 'right' | 'left' | Horizontal alignment. |
colSpan | number | — | Column span (HTML on web; visual on native). |
className | string | — | Web only. |
testID | string | — | Test identifier. |
Table.Header / Table.Body / Table.Footer / Table.Caption
Structural wrappers. Accept children, className (web), and testID.