HextaUI

Table: Sticky header

stickyHeader keeps the header in view in a height-limited table, and adds a hairline under it once rows scroll beneath.

EventTypeWhen
evt_400deploy2 min ago
evt_401rollback9 min ago
evt_402scale16 min ago
evt_403restart23 min ago
evt_404deploy30 min ago
evt_405rollback37 min ago
evt_406scale44 min ago
evt_407restart51 min ago
evt_408deploy58 min ago
evt_409rollback65 min ago
evt_40ascale72 min ago
evt_40brestart79 min ago
evt_40cdeploy86 min ago
evt_40drollback93 min ago
evt_40escale100 min ago
evt_40frestart107 min ago
evt_410deploy114 min ago
evt_411rollback121 min ago
evt_412scale128 min ago
evt_413restart135 min ago
evt_414deploy142 min ago
evt_415rollback149 min ago
evt_416scale156 min ago
evt_417restart163 min ago
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"

const events = Array.from({ length: 24 }, (_, index) => ({
  id: `evt_${(1024 + index).toString(16)}`,
  type: ["deploy", "rollback", "scale", "restart"][index % 4],
  minutes: index * 7 + 2,
}))

export function TableSticky() {
  return (
    <Table variant="surface" stickyHeader containerClassName="max-h-72">
      <TableHeader>
        <TableRow>
          <TableHead>Event</TableHead>
          <TableHead>Type</TableHead>
          <TableHead align="end">When</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {events.map((event) => (
          <TableRow key={event.id}>
            <TableCell>
              <span className="font-mono text-xs">{event.id}</span>
            </TableCell>
            <TableCell>{event.type}</TableCell>
            <TableCell align="end">{event.minutes} min ago</TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  )
}

This adds the example as components/examples/table/sticky.tsx, together with the Table component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/table-sticky.json

To add only the component, follow the Table installation.

Props in this example

The Table props this example sets, from the API reference.

PropTypeDefault
variantsurface adds a rounded hairline frame and a muted header band.
"default" | "surface""default"
stickyHeaderKeep the header in view. Give the container a max height through containerClassName.
booleanfalse
containerClassNameClasses for the scroll container.
string–
PropTypeDefault
alignend also switches to tabular numbers so digits line up.
"start" | "center" | "end""start"
PropTypeDefault
alignend also switches to tabular numbers so digits line up.
"start" | "center" | "end""start"

Every prop is in the Table API reference.

See them all, with keyboard support and accessibility notes, on the Table page.