---
product: "AG Grid"
title: "Tree Data - Overview"
description: "Tree Data provides a way to supply the grid with structured hierarchical data."
enterprise: true
framework: react
version: "36.2.0"
related:
    - title: "Supplying Data"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-data/"
    - title: "Group Column"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-group-column/"
    - title: "Expanding Groups"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-opening-groups/"
    - title: "Tree Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-selection/"
    - title: "Filtering"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-filtering/"
    - title: "Tree Row Dragging"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-row-dragging/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Tree Data - Overview

Tree Data provides a way to supply the grid with structured hierarchical data.

#### Kitchen Sink

```tsx
"use client";

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import { TreeDataModule } from "ag-grid-enterprise";
import { getData } from "./data";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

const modules = [ClientSideRowModelModule, TreeDataModule];

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);
  const [rowData, setRowData] = useState<any[]>(getData());
  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      headerName: "File Explorer",
      minWidth: 280,
      cellRendererParams: {
        suppressCount: true,
      },
    };
  }, []);
  const getDataPath = useCallback((data) => data.path, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact
            rowData={rowData}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            autoGroupColumnDef={autoGroupColumnDef}
            treeData={true}
            groupDefaultExpanded={-1}
            getDataPath={getDataPath}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Kitchen Sink](https://www.ag-grid.com/archive/36.2.0/examples/tree-data/kitchen-sink/reactFunctionalTs/)

## Enabling Tree Data

To enable Tree Data set the `treeData` property to `true` in the grid options, and provide a `getDataPath` callback to configure the [Row Hierarchy](https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-paths/). Alternatively, see how to [Provide Tree Data](https://www.ag-grid.com/archive/36.2.0/react-data-grid/tree-data-data/).

The example above uses the following configuration to enable Tree Data:

```jsx
const treeData = true;
const getDataPath = useCallback(data => data.path, []);

<AgGridReact
    treeData={treeData}
    getDataPath={getDataPath}
/>
```

## API Reference

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `treeData` | `boolean` |  |  |  |
| `getDataPath` | `GetDataPath` |  |  |  |
| `treeDataChildrenField` | `string` |  |  |  |
| `treeDataParentIdField` | `string` |  |  |  |
| `treeDataDisplayType` | `TreeDataDisplayType` |  |  |  |
| `autoGroupColumnDef` | `AutoGroupColumnDef` |  |  |  |
| `groupDefaultExpanded` | `number` |  |  |  |
| `isGroupOpenByDefault` | `IsGroupOpenByDefault` |  |  |  |
| `suppressGroupRowsSticky` | `boolean` |  |  |  |
| `stickyRowsMaxViewportRatio` | `number` |  |  |  |
