---
product: "AG Grid"
title: "Master / Detail"
description: "Master Detail refers to a top level grid called a Master Grid having rows that expand. When the row is expanded, another grid is displayed with more details related to the expanded row. The grid that appears is known as the Detail Grid."
enterprise: true
framework: react
version: "36.2.0"
related:
    - title: "Detail Grids"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-grids/"
    - title: "Detail Height"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-height/"
    - title: "Detail Refresh"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-refresh/"
    - title: "Master Rows"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-master-rows/"
    - title: "Nesting"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-nesting/"
    - title: "Custom Detail"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-custom-detail/"
    - title: "Other"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-other/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Master / Detail

Master Detail refers to a top level grid called a Master Grid having rows that expand. When the row is expanded, another grid is displayed with more details related to the expanded row. The grid that appears is known as the Detail Grid.

[Master / Detail Video Tutorial](https://www.youtube.com/watch?v=8OeJn75or2w)

## Enabling Master / Detail

Master / Detail can be enabled using the `masterDetail` grid option with detail rows configured using `detailCellRendererParams` as shown below:

```jsx
// enable Master / Detail
const masterDetail = true;
// the first Column is configured to use agGroupCellRenderer
const [columnDefs, setColumnDefs] = useState([
    { field: 'name', cellRenderer: 'agGroupCellRenderer' },
    { field: 'account' }
]);
// provide Detail Cell Renderer Params
const detailCellRendererParams = useMemo(() => { 
	return {
        // provide the Grid Options to use on the Detail Grid
        detailGridOptions: {
            columnDefs: [
                { field: 'callId' },
                { field: 'direction' },
                { field: 'number'}
            ]
        },
        // get the rows for each Detail Grid
        getDetailRowData: params => {
            params.successCallback(params.data.callRecords);
        }
    };
}, []);

<AgGridReact
    masterDetail={masterDetail}
    columnDefs={columnDefs}
    detailCellRendererParams={detailCellRendererParams}
/>
```

The example below shows a simple Master / Detail with all the above configured.

1. The grid property `masterDetail=true` is set. This tells the grid to allow expanding rows to display Detail Grids.
2. The Cell Renderer on the first column in the Master Grid is set to `agGroupCellRenderer`. This tells the grid to use the Group Cell Renderer which in turn includes the expand / collapse functionality for that column.
3. The Detail Cell Renderer parameter `detailGridOptions` is set. This contains configuration for the Detail Grid, such as which columns to display and which grid features to enable inside the Detail Grid.
4. A callback is provided via the Detail Cell Renderer parameter `getDetailRowData`. This callback is called for each Detail Grid and sets the rows to display in each Detail Grid.

> **Note**
>
> To learn more about `detailCellRendererParams` configuration see the [Detail Grids](https://www.ag-grid.com/archive/36.2.0/react-data-grid/master-detail-grids/) section.

#### Master Detail Example

```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 {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  FirstDataRenderedEvent,
  GridApi,
  GridOptions,
  IDetailCellRendererParams,
  ModuleRegistry,
  RowApiModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import { IAccount, ICallRecord } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  RowApiModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
];

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    // group cell renderer needed for expand / collapse icons
    { field: "name", cellRenderer: "agGroupCellRenderer" },
    { field: "account" },
    { field: "calls" },
    { field: "minutes", valueFormatter: "x.toLocaleString() + 'm'" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
    };
  }, []);
  const detailCellRendererParams = useMemo(() => {
    return {
      detailGridOptions: {
        columnDefs: [
          { field: "callId" },
          { field: "direction" },
          { field: "number", minWidth: 150 },
          { field: "duration", valueFormatter: "x.toLocaleString() + 's'" },
          { field: "switchCode", minWidth: 150 },
        ],
        defaultColDef: {
          flex: 1,
        },
      },
      getDetailRowData: (params) => {
        params.successCallback(params.data.callRecords);
      },
    } as IDetailCellRendererParams<IAccount, ICallRecord>;
  }, []);

  const { data, loading } = useFetchJson<IAccount>(
    "https://www.ag-grid.com/example-assets/master-detail-data.json",
  );

  const onFirstDataRendered = useCallback((params: FirstDataRenderedEvent) => {
    // arbitrarily expand a row for presentational purposes
    setTimeout(() => {
      params.api.getDisplayedRowAtIndex(1)!.setExpanded(true);
    }, 0);
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IAccount>
            rowData={data}
            loading={loading}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            masterDetail={true}
            detailCellRendererParams={detailCellRendererParams}
            onFirstDataRendered={onFirstDataRendered}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Master Detail Example](https://www.ag-grid.com/archive/36.2.0/examples/master-detail/simple/reactFunctionalTs/)

## Row Models

When using Master / Detail the Master Grid must be using either the [Client-Side](https://www.ag-grid.com/archive/36.2.0/react-data-grid/row-models/#client-side) or [Server-Side](https://www.ag-grid.com/archive/36.2.0/react-data-grid/server-side-model-master-detail/) Row Models. It is not supported with the [Viewport](https://www.ag-grid.com/archive/36.2.0/react-data-grid/viewport/) or [Infinite](https://www.ag-grid.com/archive/36.2.0/react-data-grid/infinite-scrolling/) Row Models.

The Detail Grid on the other hand can use any Row Model.

## API Reference

### Master Detail Properties

Top level Master Detail properties available on the Grid Options:

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `masterDetail` | `boolean` |  |  |  |
| `isRowMaster` | `IsRowMaster` |  |  |  |
| `masterDefaultExpanded` | `number` |  |  |  |
| `isMasterOpenByDefault` | `IsMasterOpenByDefault` |  |  |  |
| `detailCellRenderer` | `any` |  |  |  |
| `detailCellRendererParams` | `any` |  |  |  |
| `detailRowHeight` | `number` |  |  |  |
| `detailRowAutoHeight` | `boolean` |  |  |  |
| `keepDetailRows` | `boolean` |  |  |  |
| `keepDetailRowsCount` | `number` |  |  |  |

### Detail Cell Renderer Params

Properties available on the `IDetailCellRendererParams&lt;TData = any, TDetail = any&gt;` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `detailGridOptions` | `GridOptions<TDetail>` |  |  |  |
| `getDetailRowData` | `GetDetailRowData<TData, TDetail>` |  |  |  |
| `refreshStrategy` | `'rows' \| 'everything' \| 'nothing'` |  |  |  |
