pearpages

Data Grid

Component

About

An accessible, sortable and selectable data table built on React Aria's grid pattern, for displaying rows of structured records with keyboard navigation.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Data Grid to your project and fits it to your theme.

Code

How Data Grid is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import { DataGrid } from "@/components/ui/data-grid";

interface Person {
  id: string;
  name: string;
  role: string;
  team: string;
}

const people: Person[] = [
  { id: "p1", name: "Alice Martin", role: "Engineer", team: "Platform" },
  { id: "p2", name: "Bob Chen", role: "Designer", team: "Product" },
  { id: "p3", name: "Carla Ruiz", role: "Manager", team: "Platform" },
  { id: "p4", name: "Dmitri Volkov", role: "Engineer", team: "Data" },
];

export default function DataGridSelectionDemo() {
  const [selected, setSelected] = React.useState<string[]>(["p2"]);

  return (
    <div
      className="w-full p-6"
      style={{ background: "var(--color-surface-base)" }}
    >
      <DataGrid
        aria-label="Team members"
        selectionMode="multiple"
        selected={selected}
        onSelectedChange={setSelected}
        disabledIds={["p4"]}
      >
        <DataGrid.Header>
          <DataGrid.Column id="name" isRowHeader>
            Name
          </DataGrid.Column>
          <DataGrid.Column id="role">Role</DataGrid.Column>
          <DataGrid.Column id="team">Team</DataGrid.Column>
        </DataGrid.Header>
        <DataGrid.Body items={people}>
          {(person) => (
            <DataGrid.Row>
              <DataGrid.Cell>{person.name}</DataGrid.Cell>
              <DataGrid.Cell>{person.role}</DataGrid.Cell>
              <DataGrid.Cell>{person.team}</DataGrid.Cell>
            </DataGrid.Row>
          )}
        </DataGrid.Body>
      </DataGrid>
    </div>
  );
}

Dependencies

More by pearpages

View all
  • Popover

    Popover

    6
  • Slider

    Slider

  • Switch

    Switch

  • Tabs

    Tabs

  • Text Field

    Text Field