Data Table

You declare the columns and it sorts, searches (accent-insensitive), paginates, selects rows with bulk actions and shows/hides columns. Empty, no-results and loading states are ready. No table library.

Show columns

Pedidos da loja, sorted by Data
#5120Marina CoutoRecife28 de setPagoR$ 77,20
#5127Rafael NogueiraBelo Horizonte27 de setEnviadoR$ 306,40
#5134Júlia AlbuquerqueSão Paulo26 de setPagoR$ 535,60
#5141Otávio MendesCuritiba25 de setAguardandoR$ 134,50
#5148Beatriz SáSalvador23 de setEnviadoR$ 363,70

Settings

Estado
Por página
Densidade
Toggles

Examples

Controlled selection

1 pedido na próxima remessa · 6 itens

1 selected
Pedidos para enviar
#5120Marina Couto1
#5127Rafael Nogueira6
#5134Júlia Albuquerque4
#5141Otávio Mendes2
#5148Beatriz Sá7

Updating without jumping

Pedidos recentes
#5120Marina CoutoPagoR$ 77,20
#5127Rafael NogueiraEnviadoR$ 306,40
#5134Júlia AlbuquerquePagoR$ 535,60
#5141Otávio MendesAguardandoR$ 134,50

Scrolling with a sticky header

Todos os pedidos, sorted by Total
#5176Ana Clara RibeiroR$ 650,20
#5253Bruno EstevesR$ 650,20
#5155Caio LinharesR$ 592,90
#5232Helena DuarteR$ 592,90
#5134Júlia AlbuquerqueR$ 535,60
#5211Pedro AssunçãoR$ 535,60
#5190Sofia AntunesR$ 478,30
#5267Lucas PimentelR$ 478,30
#5169Henrique TavaresR$ 421,00
#5246Camila FreitasR$ 421,00
#5148Beatriz SáR$ 363,70
#5225Gustavo LeiteR$ 363,70
#5127Rafael NogueiraR$ 306,40
#5204Lara MenezesR$ 306,40
#5183Diego FariasR$ 249,10
#5260Yasmin CorreiaR$ 249,10
#5162Letícia PradoR$ 191,80
#5239Tiago BarretoR$ 191,80
#5141Otávio MendesR$ 134,50
#5218Isabela RochaR$ 134,50
#5120Marina CoutoR$ 77,20
#5197Mateus CarvalhoR$ 77,20
#5274Elisa MonteiroR$ 77,20

Installation

The command creates components/ui/data-table.tsx in your project and installs the theme with it. The file is yours: edit it as you like.

npx @ravox-ui/cli add data-table

Props

PropTypeDefaultDescription
dataT[]—The rows. They stay on the client: for thousands of records, paginate on the server and pass only the page.
columnsDataTableColumn<T>[]—{ key, title, value?, cell?, numeric?, sortable?, searchable?, hideable?, hidden?, width? }. value is for sorting and searching; cell is for rendering.
rowKey(row: T) => string—Unique id of each row (selection and key).
labelstring—Table name: becomes the caption for screen readers and the name of the search and pagination.
searchbooleantrueSearch field over the text columns (or the ones marked searchable). Esc clears it.
pageSizenumber10Rows per page. 0 turns pagination off.
pageSizeOptionsnumber[][10, 25, 50]Options for "Rows per page". With only one, the selector disappears.
selectablebooleanfalseCheckbox column. The header one selects the page and offers to select all results.
selected / onSelectionChangestring[] / (ids: string[]) => void—Controlled selection (rowKey ids). Without selected, it keeps the selection itself.
bulkActions(selected: T[], clear: () => void) => ReactNode—Buttons in the bar that appears when rows are selected.
initialSort{ key, direction: "asc" | "desc" } | null—Initial order. Clicking the title cycles through ascending, descending and no order; aria-sort follows.
columnMenubooleantrue"Columns" button to hide and show columns (the last visible one can't be hidden).
loadingbooleanfalseWithout data: skeleton rows. With data: keeps the previous screen dimmed, without jumping.
emptyReactNode—What appears when data comes in empty. A search with no results has its own message with "Clear search".
extraReactNode—Something on the right of the bar (e.g. a "New customer" button).
density"compact" | "normal" | "relaxed""normal"Passed on to Table.
maxHeightnumber | string—With it, the body scrolls and the header sticks to the top.

More in Data