

<Preview name="InteractiveStatesExample" />

## Overview [#overview]

`DataTable` has built-in rendering paths for loading, empty, and error states so the surrounding layout does not need to branch around the table container.

## Loading [#loading]

Set `loading` to render skeleton rows. By default the table uses a generic skeleton for each cell.

```tsx
<DataTable
  columns={columns}
  data={[]}
  loading
  skeletonRowCount={8}
/>
```

## Empty and Error [#empty-and-error]

Pass an `emptyState` object when the zero-rows case needs product copy or a URL-trigger action. Pass `error` when loading failed and you want the table to render an error row instead.

```tsx
<DataTable
  columns={columns}
  data={[]}
  emptyState={{
    title: "No employees found",
    description: "Get started by adding your first employee",
    action: {
      label: "Add employee",
      paramName: "dialog",
      paramSetValue: "add-employee",
    },
  }}
  error={loadError ? "Failed to load employees" : null}
/>
```

## Custom Skeletons [#custom-skeletons]

Use `ColumnDef.meta.skeleton` when a column needs a more realistic placeholder shape.

<Preview name="CustomSkeletonExample" />

## Component Overrides [#component-overrides]

For fully custom loading or error rendering, override the table-level state components:

```tsx
<DataTable
  columns={columns}
  data={data}
  components={{
    LoadingState: ({ colSpan }) => <tr><td colSpan={colSpan}>Loading...</td></tr>,
    ErrorState: ({ colSpan, error }) => <tr><td colSpan={colSpan}>{error}</td></tr>,
  }}
/>
```

## API Reference [#api-reference]

| Prop / Field              | Type                                                | Description                                                      |
| ------------------------- | --------------------------------------------------- | ---------------------------------------------------------------- |
| `loading`                 | `boolean`                                           | Show the loading state with skeleton rows                        |
| `error`                   | `string \| null \| undefined`                       | Show the error state with the provided message                   |
| `skeletonRowCount`        | `number \| "auto"`                                  | Number of skeleton rows, or auto-calculate from container height |
| `emptyState`              | object                                              | Empty-state copy, icon, and optional action                      |
| `components.LoadingState` | `ComponentType<{ colSpan: number }>`                | Replace the default loading row                                  |
| `components.ErrorState`   | `ComponentType<{ colSpan: number; error: string }>` | Replace the default error row                                    |
| `ColumnDef.meta.skeleton` | `() => ReactNode`                                   | Customize the loading skeleton for one column                    |
