Grid table

A table laid out with CSS grid, for column sizes a native table can't express and rows built from any element.

React

File
Owner
Size
brand-guidelines.pdf
Design
4.2 MB
roadmap-2027.key
Product
18.9 MB
invoice-0042.csv
Finance
12 KB

The same look as Table, built from divs with table roles. The columns come from one grid template, and rows use subgrid, so every row lines up with the header however the columns are sized.

Usage

import { GridTable } from "@isbatak/react-ui/grid-table"

export function GridTableDemo() {
  return (
    <GridTable.Root columns="minmax(8rem, 2fr) minmax(6rem, 1fr) auto">
      <GridTable.Header>
        <GridTable.HeaderRow>
          <GridTable.ColumnHeader>File</GridTable.ColumnHeader>
          <GridTable.ColumnHeader>Owner</GridTable.ColumnHeader>
          <GridTable.ColumnHeader justifyContent="flex-end">Size</GridTable.ColumnHeader>
        </GridTable.HeaderRow>
      </GridTable.Header>
      <GridTable.Body>
        <GridTable.Row>
          <GridTable.Cell>brand-guidelines.pdf</GridTable.Cell>
          <GridTable.Cell>Design</GridTable.Cell>
          <GridTable.Cell justifyContent="flex-end">4.2 MB</GridTable.Cell>
        </GridTable.Row>
        <GridTable.Row>
          <GridTable.Cell>roadmap-2027.key</GridTable.Cell>
          <GridTable.Cell>Product</GridTable.Cell>
          <GridTable.Cell justifyContent="flex-end">18.9 MB</GridTable.Cell>
        </GridTable.Row>
        <GridTable.Row>
          <GridTable.Cell>invoice-0042.csv</GridTable.Cell>
          <GridTable.Cell>Finance</GridTable.Cell>
          <GridTable.Cell justifyContent="flex-end">12 KB</GridTable.Cell>
        </GridTable.Row>
      </GridTable.Body>
    </GridTable.Root>
  )
}
<GridTable.Root columns="2fr 1fr auto">
  <GridTable.Header>
    <GridTable.HeaderRow>
      <GridTable.ColumnHeader />
    </GridTable.HeaderRow>
  </GridTable.Header>
  <GridTable.Body>
    <GridTable.Row>
      <GridTable.Cell />
    </GridTable.Row>
  </GridTable.Body>
</GridTable.Root>

columns is a grid-template-columns value, set on the root as --grid-template-columns. The default fits as many 10rem columns as there is room for.

Examples

Sticky header and columns

The root scrolls, so give it a maxH and stickyHeader keeps the header in view. Pass sticky="start" or sticky="end" to GridTable.ColumnHeader and GridTable.Cell to pin a column.

Service
Region
Instances
Uptime
Status
api-gateway
eu-west-1
3
99.98%
Healthy
auth-service
us-east-1
5
99.95%
Healthy
billing-worker
eu-west-1
2
99.40%
Degraded
search-index
ap-south-1
4
99.99%
Healthy
media-encoder
us-west-2
6
99.90%
Healthy
notifications
eu-central-1
3
98.70%
Degraded
reports
us-east-1
1
99.99%
Healthy
webhooks
eu-west-1
2
99.97%
Healthy

Interactive and borders

interactive highlights rows on hover, selected on GridTable.Row marks a row, and showColumnBorder adds borders between columns. size and showRowBorder work as they do on Table.

Branch
Author
Checks
main
ivica
Passing
feat/toc
ivica
Running
fix/drawer
ana
Failing

Recipe

VariantValuesDefault
sizesm, md, lgmd
showRowBordertrue, falsetrue
showColumnBordertrue, false
interactivetrue
stickyHeadertrue
highlightedHeadertrue

The variables are the same as Table's, plus --grid-template-columns.