# Getting started
Package: @mantine/data-grid
Description: Get started with @mantine/data-grid package

## Installation

Install `@mantine/data-grid` and its peer dependencies:

```bash
yarn add @mantine/data-grid @tanstack/react-table @tanstack/react-virtual @tanstack/match-sorter-utils
```

```bash
npm install @mantine/data-grid @tanstack/react-table @tanstack/react-virtual @tanstack/match-sorter-utils
```

Import the package styles after `@mantine/core` styles:

```tsx
import '@mantine/core/styles.css';
import '@mantine/data-grid/styles.css';
```

## Quick start

```tsx
import { DataGrid } from '@mantine/data-grid';

const data = [
  { id: '1', name: 'Alice', age: 30 },
  { id: '2', name: 'Bob', age: 25 },
];

function Demo() {
  return (
    <DataGrid
      data={data}
      columns={[
        { accessorKey: 'name', header: 'Name' },
        { accessorKey: 'age', header: 'Age' },
      ]}
    />
  );
}
```

## Store hook

Use `useDataGrid` to create a store that manages grid state and pass it to `DataGrid`
with the `store` prop:

```tsx
import { DataGrid, useDataGrid } from '@mantine/data-grid';

function Demo() {
  const store = useDataGrid({
    data,
    columns: [
      { accessorKey: 'name', header: 'Name', enableSorting: true },
      { accessorKey: 'age', header: 'Age' },
    ],
  });

  return <DataGrid store={store} />;
}
```

## createDataGridColumnHelper

`createDataGridColumnHelper` is a wrapper around TanStack Table `createColumnHelper`.
Pass your row data type as a generic to get autocompletion on accessor keys and cell values:

```tsx
import { createDataGridColumnHelper, DataGrid, useDataGrid } from '@mantine/data-grid';

const columnHelper = createDataGridColumnHelper<Person>();

const columns = [
  columnHelper.accessor('name', { header: 'Name', enableSorting: true }),
  columnHelper.accessor('age', { header: 'Age' }),
  columnHelper.display({
    id: 'actions',
    meta: { type: 'actions' },
    cell: () => <Button size="xs">Edit</Button>,
  }),
];
```

## Column definition types

TanStack Table supports three kinds of column definitions:

* **Accessor columns** – defined with `accessorKey` or `accessorFn`. Read data from the row and support sorting, filtering and grouping.
* **Display columns** – defined with an `id` and no accessor. Used for action buttons, checkboxes or any content not tied to row data.
* **Group columns** – defined with a `columns` array. Create a multi-level header by nesting other columns inside a group.

## defaultColumn

Pass `defaultColumn` in `tableOptions` to set default values of column properties:

```tsx
const store = useDataGrid({
  data,
  columns,
  tableOptions: {
    defaultColumn: { size: 200, minSize: 50, maxSize: 500 },
  },
});
```

## Features overview

Features are configured with `useDataGrid` options. Most of them are enabled automatically
when you pass controlled state or column-level flags:

Set the matching `with*` option (for example, `withSorting`) to force a feature on or off.
Appearance props such as `striped` or `withColumnBorders` are set on the `DataGrid` component,
see [Customization](https://alpha.mantine.dev/llms/data-grid-customization.md).

## Peer dependencies

`@mantine/data-grid` has the following peer dependencies:
