Table

Table views are used to display data in a tabular format. They are useful for displaying large amounts of data in a structured way.

Installation

npx love-ui@latest add table

Usage

import { TableProvider, TableHeader, TableHeaderGroup, TableHead, TableBody, TableRow, TableCell, TableColumnHeader, type ColumnDef } from "@/components/table"
const columns: ColumnDef<Data>[] = [
  {
    accessorKey: "name",
    header: ({ column }) => <TableColumnHeader column={column} title="Name" />,
  },
  // ... more columns
]
 
<TableProvider columns={columns} data={data}>
  <TableHeader>
    {(headerGroup) => (
      <TableHeaderGroup key={headerGroup.id}>
        {headerGroup.headers.map((header) => (
          <TableHead key={header.id} header={header} />
        ))}
      </TableHeaderGroup>
    )}
  </TableHeader>
  <TableBody>
    {(row) => (
      <TableRow key={row.id} row={row}>
        {row.getVisibleCells().map((cell) => (
          <TableCell key={cell.id} cell={cell} />
        ))}
      </TableRow>
    )}
  </TableBody>
</TableProvider>

Features

  • Customizable columns
  • Sortable columns

Examples

Simple version