# Tables and Data grid

Display records in a table or let people edit them in a spreadsheet-style grid.

See [Choose a table or chart](/articles/choosing-data-views) if you’re deciding how people should explore the data.

## Choose Table or Data grid

Use [Table](/components/table) for reports and lists read row by row. Use [Data grid](/components/data-grid) when people need to move between cells, select ranges, or edit values.

Both views can share a TanStack Table instance. TanStack handles column accessors and the current rows after sorting, filtering, or paging. Your app fetches data, validates edits, and saves changes.

## Render your first table

Install [Ghost UI and its component styles](/docs/installation#package), then use TanStack Table v9 for this example.

```bash
npm install @tanstack/react-table@9.2.8
```

Render Sources. You should see two columns, Source and Owner, with one row for Handbook.pdf.

```tsx
import { tableFeatures, useTable, type ColumnDef } from "@tanstack/react-table";
import { Table } from "@collectivecreation/ghost-ui/components/table";

type Source = { id: string; title: string; owner: string };
const features = tableFeatures({});
const rows: Source[] = [{ id: "handbook", title: "Handbook.pdf", owner: "Mira" }];
const columns: ColumnDef<typeof features, Source>[] = [
  { accessorKey: "title", header: "Source" },
  { accessorKey: "owner", header: "Owner" },
];
export function Sources() {
  const table = useTable({ features, data: rows, columns, getRowId: row => row.id });
  return <Table aria-label="Sources"><Table.Data table={table} /></Table>;
}

```

Use accessorKey to read a row property. For a computed value, use accessorFn and give the column a stable id. Stable row and column IDs keep selection, edits, and pinning on the right records when the order changes.

## Add sorting and other features

For client-side sorting, register rowSortingFeature in tableFeatures and configure the sorted row model. Filtering and pagination each need their own feature and row model.

Table.Data subscribes to the instance and renders headers and cells with table.FlexRender. Configure alignment and width with meta.alignment and meta.widthMode. For a custom cell layout, compose the Table parts directly.

Continue with [state and editing](/libraries/table-state). Use the [TanStack v9 guides](https://tanstack.com/table/latest/docs/guide/tables) for engine details, and the component pages for anatomy and styling.

## Reference and troubleshooting

TableDataProps accepts table, emptyContent, showFooter, and row/header/cell prop callbacks. DataGridTableProps accepts table plus grid interaction props, excluding raw rows/columns. Import these types from their respective component subpaths. [Table API](/components/table#api) and [Data grid API](/components/data-grid#api-reference) describe the exact view contracts.

- A feature method is missing. Check the feature registration and TanStack major version. The v8 useReactTable examples use a different API.

- A separate control shows old state. Subscribe to the relevant table state with table.Subscribe.

- An edit disappears. Apply it to your app’s rows and save it if it should persist.
