Table
Loading example…
Table inside its own horizontal scroll wrapper. Give columns a columnId (header and cells)
and mark header cells pinnable to let the user pin them to the left or right edge: pinned
columns stay sticky while the rest scrolls.
Import
Section titled “Import”import { Table } from "@jcsoftdev/ui/containers";Single-component entry points tree-shake to just this component: @jcsoftdev/ui/containers/table.
<Table aria-label="Inventario de productos"> <> <TableHead> <tr> <TableHeaderCell>Producto</TableHeaderCell> <TableHeaderCell>SKU</TableHeaderCell> <TableHeaderCell alignRight>Stock</TableHeaderCell> <TableHeaderCell alignRight>Precio</TableHeaderCell> </tr> </TableHead> <TableBody> {inventory.map((item) => ( <TableRow key={item.sku}> <TableCell> {item.name} {item.low ? <Chip tone="danger">Stock bajo</Chip> : null} </TableCell> <TableCell>{item.sku}</TableCell> <TableCell alignRight>{item.stock}</TableCell> <TableCell alignRight>{item.price}</TableCell> </TableRow> ))} </TableBody> </></Table>| Prop | Type | Default | Description |
|---|---|---|---|
pinnedColumns |
PinnedColumns |
Controlled pinned columns (ids of columnId). Pair it with onPinnedColumnsChange. |
|
defaultPinnedColumns |
PinnedColumns |
Initial pins when uncontrolled. | |
onPinnedColumnsChange |
((pinned: { left: string[]; right: string[]; }) => void) |
||
pinStorageKey |
string |
localStorage key that remembers the user’s pins (uncontrolled only). | |
labels |
Partial<TableLabels> |
Texts of the pin buttons (Spanish by default). | |
wrapperClassName |
string |
Classes of the scroll wrapper. | |
flush |
boolean | "end" | "start" |
Drops the outer cell padding of the first ("start"), last ("end") or both (true) columns, so their content sits on the container edge and the page layout owns the gutter. The padding between columns stays. |
|
stickyHeader |
boolean |
Keeps the header row in view while the body scrolls. It sticks inside the scroll wrapper, so give the table a maxHeight (or a bounded wrapperClassName) for it to have anything to scroll. |
|
maxHeight |
Property.MaxHeight<string | number> |
Caps the wrapper height; the body scrolls vertically past it. Any CSS length. | |
selectedKeys |
readonly string[] |
Controlled selected row keys (the rowKey of each TableRow). Setting it turns selection on. |
|
defaultSelectedKeys |
readonly string[] |
Initial selected keys when uncontrolled. Setting it turns selection on. | |
onSelectedKeysChange |
((keys: string[]) => void) |
Called with the next keys. Setting it turns selection on. | |
sort |
TableSort | null |
Controlled sort state. Setting it, defaultSort or onSortChange turns sorting on for the headers marked sortable. The table only reports the state: sort your rows yourself. |
|
defaultSort |
TableSort | null |
Initial sort when uncontrolled. | |
onSortChange |
((sort: TableSort | null) => void) |
Called with the next sort (null when the sort is cleared). |
|
hiddenColumns |
readonly string[] |
Ids (columnId) of the columns to hide. Headers and cells with that id render nothing. |
|
density |
"compact" | "comfortable" |
"comfortable" |
Row density: comfortable (default) gives every body row at least 48px, compact 40px, with the cells centred vertically. Rows never depend on what a cell holds for their height. |
stickyActions |
boolean |
Keeps the last column (the row actions) stuck to the right edge while the table scrolls sideways, from 24rem of the table’s own width up. Leave the last column unpinned when using it. |
* marks a required prop.
It also accepts the native props of the element or primitive it renders (for example className, id, aria-* and event handlers).
Storybook stories
Section titled “Storybook stories”- Default
- Link Rows
- Empty
- PinnedColumns
- User Pinning
- Controlled Pinning
- Narrow
- Flush
- Sticky Header
- Selection
- Actions Wide
- Actions Narrow Menu
- Actions Narrow Wrap
- Sortable
- Loading And Empty
- Column Visibility
- Density
- Sticky Actions
Source
Section titled “Source”packages/ui/src/containers/table/table.tsx