# Data Grid

Advanced data grid with sorting, filtering, pagination, and cell editing



<ComponentPreview base="opentui" name="data-grid-demo" />

Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @termcn/opentui-data-grid
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource base="opentui" name="data-grid" title="components/ui/data-grid.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

Usage [#usage]

```tsx
import { DataGrid } from "@/components/ui/data-grid";
```

```tsx
<DataGrid
  data={[
    { name: "Alice", role: "Engineer", status: "Active" },
    { name: "Bob", role: "Designer", status: "Away" },
  ]}
  columns={[
    { key: "name", header: "Name", width: 12 },
    { key: "role", header: "Role", width: 12 },
    { key: "status", header: "Status", width: 10 },
  ]}
/>
```

API Reference [#api-reference]

DataGrid [#datagrid]

| Prop                | Type                                           | Default    |
| ------------------- | ---------------------------------------------- | ---------- |
| `data`              | `T[]`                                          | `required` |
| `columns`           | `DataGridColumn<T>[]`                          | `required` |
| `pageSize`          | `number`                                       | `10`       |
| `onRowSelect`       | `(row: T) => void`                             | -          |
| `onCellEdit`        | `(row: T, key: string, value: string) => void` | -          |
| `borderColor`       | `string`                                       | -          |
| `borderStyle`       | `"single" \| "double" \| "round" \| "bold"`    | `"single"` |
| `showRowNumbers`    | `boolean`                                      | `false`    |
| `filterPlaceholder` | `string`                                       | -          |

DataGridColumn [#datagridcolumn]

| Prop         | Type                                 | Default    |
| ------------ | ------------------------------------ | ---------- |
| `key`        | `keyof T & string`                   | `required` |
| `header`     | `string`                             | `required` |
| `width`      | `number`                             | -          |
| `align`      | `"left" \| "right" \| "center"`      | `"left"`   |
| `render`     | `(value: unknown, row: T) => string` | -          |
| `filterable` | `boolean`                            | -          |
| `sortable`   | `boolean`                            | -          |
