---
title: "Custom Detail"
enterprise: true
framework: vue
version: "36.1.0"
---

# Custom Detail

When a Master Row is expanded, the grid uses the default Detail Cell Renderer to create and display the Detail Grid inside one row of the Master Grid. You can provide a custom Detail Cell Renderer to display something else if the default Detail Cell Renderer doesn't do what you want.

Configure the grid to use a custom Detail Cell Renderer using the grid property `detailCellRenderer`.

```ts
<ag-grid-vue
    :detailCellRenderer="detailCellRenderer"
    :detailCellRendererParams="detailCellRendererParams"
    /* other grid options ... */>
</ag-grid-vue>

// normally left blank, the grid will use the default Detail Cell Renderer
this.detailCellRenderer = 'myCellRendererComp';
// params sent to the Detail Cell Renderer, in this case your MyCellRendererComp
this.detailCellRendererParams = {};
```

The Detail Cell Renderer should be a [Cell Renderer](https://www.ag-grid.com/vue-data-grid/component-cell-renderer/) component. See [Cell Renderer](https://www.ag-grid.com/vue-data-grid/component-cell-renderer/) on how to build and register a Cell Renderer with the grid.

The following examples demonstrate minimalist custom Detail Cell Renderer. Note that where a Detail Grid would normally appear, only the message "My Custom Detail" is shown.

#### Simple Detail Cell Renderer

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  FirstDataRenderedEvent,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  RowApiModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import DetailCellRenderer from "./detailCellRendererVue";
import { IAccount } from "./interfaces";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowApiModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <ag-grid-vue
      style="width: 100%; height: 100%;"
      @grid-ready="onGridReady"
      :masterDetail="true"
      :detailCellRenderer="detailCellRenderer"
      :columnDefs="columnDefs"
      :defaultColDef="defaultColDef"
      :rowData="rowData"
      @first-data-rendered="onFirstDataRendered"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
    DetailCellRenderer,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IAccount> | null>(null);
    const detailCellRenderer = ref("DetailCellRenderer");
    const columnDefs = ref<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 = ref<ColDef>({
      flex: 1,
    });
    const rowData = ref<IAccount[]>(null);

    function onFirstDataRendered(params: FirstDataRenderedEvent) {
      params.api.forEachNode(function (node) {
        node.setExpanded(node.id === "1");
      });
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/master-detail-data.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      detailCellRenderer,
      columnDefs,
      defaultColDef,
      rowData,
      onGridReady,
      onFirstDataRendered,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Simple Detail Cell Renderer](https://www.ag-grid.com/examples/master-detail-custom-detail/simple-custom-detail/vue3)

## Custom Detail With Form

It is not mandatory to display a grid inside the detail section. As you are providing a custom component, there are no restrictions as to what can appear inside the custom component.

This example shows a custom Detail Cell Renderer that uses a form rather than a grid.

#### Custom Detail Cell Renderer with Form

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  FirstDataRenderedEvent,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  RowApiModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import DetailCellRenderer from "./detailCellRendererVue";
import { IAccount } from "./interfaces";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowApiModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <ag-grid-vue
      style="width: 100%; height: 100%;"
      @grid-ready="onGridReady"
      :columnDefs="columnDefs"
      :defaultColDef="defaultColDef"
      :masterDetail="true"
      :detailCellRenderer="detailCellRenderer"
      :detailRowHeight="detailRowHeight"
      :groupDefaultExpanded="groupDefaultExpanded"
      :rowData="rowData"
      @first-data-rendered="onFirstDataRendered"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
    DetailCellRenderer,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IAccount> | null>(null);
    const columnDefs = ref<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 = ref<ColDef>({
      flex: 1,
    });
    const detailCellRenderer = ref("DetailCellRenderer");
    const detailRowHeight = ref(80);
    const groupDefaultExpanded = ref(1);
    const rowData = ref<IAccount[]>(null);

    function onFirstDataRendered(params: FirstDataRenderedEvent) {
      params.api.forEachNode(function (node) {
        node.setExpanded(node.id === "1");
      });
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/master-detail-data.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      detailCellRenderer,
      detailRowHeight,
      groupDefaultExpanded,
      rowData,
      onGridReady,
      onFirstDataRendered,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Custom Detail Cell Renderer with Form](https://www.ag-grid.com/examples/master-detail-custom-detail/custom-detail-with-form/vue3)

## Custom Detail With Grid

It is possible to provide a Custom Detail Grid that does a similar job to the default Detail Cell Renderer. This example demonstrates displaying a custom grid as the detail. Details are logged to the developer console.

#### Custom Detail Cell Renderer with Grid

```ts
import { createApp, defineComponent } from "vue";

import type {
  ChartRef,
  ColDef,
  FirstDataRenderedEvent,
  GridApi,
  GridReadyEvent,
} from "ag-grid-community";
import {
  ClientSideRowModelApiModule,
  ClientSideRowModelModule,
  ModuleRegistry,
  RowApiModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import { AgGridVue } from "ag-grid-vue3";

import DetailCellRenderer from "./detailCellRendererVue";
import "./styles.css";

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

ModuleRegistry.registerModules([
  ClientSideRowModelApiModule,
  RowApiModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
            <div class="example-wrapper">
                <div style="margin-bottom: 5px;">
                    <button v-on:click="printDetailGridInfo()">Print Detail Grid Info</button>
                    <button v-on:click="expandCollapseAll()">Toggle Expand / Collapse</button>
                </div>
                <ag-grid-vue
                        style="width: 100%; height: 100%;"
                        id="myGrid"
                        :columnDefs="columnDefs"
                        @grid-ready="onGridReady"
                        :defaultColDef="defaultColDef"
                        :masterDetail="true"
                        :detailRowHeight="detailRowHeight"
                        :detailCellRenderer="detailCellRenderer"
                        :rowData="rowData"
                        @first-data-rendered="onFirstDataRendered"></ag-grid-vue>
            </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
    myDetailCellRenderer: DetailCellRenderer,
  },
  data: function () {
    return {
      columnDefs: <ColDef[]>[
        {
          field: "name",
          cellRenderer: "agGroupCellRenderer",
        },
        { field: "account" },
        { field: "calls" },
        {
          field: "minutes",
          valueFormatter: "x.toLocaleString() + 'm'",
        },
      ],
      gridApi: null,
      defaultColDef: <ColDef>{ flex: 1 },
      detailRowHeight: null,
      detailCellRenderer: null,
      rowData: null,
    };
  },
  beforeMount() {
    this.detailRowHeight = 310;
    this.detailCellRenderer = "myDetailCellRenderer";
  },
  methods: {
    onFirstDataRendered(params: FirstDataRenderedEvent) {
      setTimeout(function () {
        params.api.getDisplayedRowAtIndex(1).setExpanded(true);
      }, 0);
    },
    expandCollapseAll() {
      this.gridApi.forEachNode(function (node) {
        node.expanded = !!window.collapsed;
      });
      window.collapsed = !window.collapsed;
      this.gridApi.onGroupExpandedOrCollapsed();
    },
    printDetailGridInfo() {
      console.log("Currently registered detail grid's: ");
      this.gridApi.forEachDetailGridInfo(function (detailGridInfo) {
        console.log(detailGridInfo);
      });
    },
    onGridReady(params: GridReadyEvent) {
      this.gridApi = params.api;

      const updateData = (data) => {
        this.rowData = data;
      };

      fetch("https://www.ag-grid.com/example-assets/master-detail-data.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    },
  },
});

createApp(VueExample).mount("#app");
```

[Live example: Custom Detail Cell Renderer with Grid](https://www.ag-grid.com/examples/master-detail-custom-detail/custom-detail-with-grid/vue3)

## Register Detail Grid

In order for the Detail Grid's API to be available via the Master Grid as explained in [Accessing Detail Grids](https://www.ag-grid.com/vue-data-grid/master-detail-grids/#accessing-detail-grids), a Grid Info object needs to be registered with the Master Grid.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `addDetailGridInfo` | `Function` |  |  | Register a detail grid with the master grid when it is created. Module: [`MasterDetailModule`](https://www.ag-grid.com/vue-data-grid/modules/). |
| `removeDetailGridInfo` | `Function` |  |  | Unregister a detail grid from the master grid when it is destroyed. Module: [`MasterDetailModule`](https://www.ag-grid.com/vue-data-grid/modules/). |

When the Detail Grid is created, register it via `masterGridApi.addDetailGridInfo(id, info)` and when the Detail Grid is destroyed, unregister it via `masterGridApi.removeDetailGridInfo(id)`. A Detail ID is required when calling these methods. Any unique ID can be used, however for consistency with how the default Detail Cell Renderer works it's recommended to use the ID of the detail Row Node.

```js
//////////////////////////////
// Register with Master Grid
const detailId = params.node.id;

// Create Grid Info object
const detailGridInfo = {
    id: detailId,
    api: params.api,
};

this.masterGridApi.addDetailGridInfo(detailId, detailGridInfo);

//////////////////////////////
// Unregister with Master Grid
this.masterGridApi.removeDetailGridInfo(detailId);
```

## Custom Detail Height

When using a custom Detail Cell Renderer the height of the detail section can be customised as explained in [Detail Height](https://www.ag-grid.com/vue-data-grid/master-detail-height/).

## Refreshing

When data is updated in the grid using [Transaction Updates](https://www.ag-grid.com/vue-data-grid/data-update-transactions/), the grid will call refresh on all Detail Cell Renderers.

It is up to the Detail Cell Renderer whether it wants to act on the refresh or not. If the `refresh()` method returns `true`, the grid will assume the Detail Cell Renderer has refreshed successfully and nothing more will happen. However if `false` is returned, the grid will destroy the Detail Cell Renderer and re-create it again.

This pattern is similar to how refresh works for normal grid Cell Renderers.

The example below shows how components can refresh on updates. The example refreshes the first row every one second. The `refresh()` method gets called on the corresponding Detail Cell Renderer after the transaction is applied. The Detail Cell Renderer refresh method reads the latest call count from the params, and the last updated time is also changed.

#### Custom Detail with Refresh

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelApiModule,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  FirstDataRenderedEvent,
  GridApi,
  GridOptions,
  GridReadyEvent,
  HighlightChangesModule,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import DetailCellRenderer from "./detailCellRendererVue";
import { IAccount } from "./interfaces";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  ClientSideRowModelApiModule,
  HighlightChangesModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

let allRowData: any[];

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <ag-grid-vue
      style="width: 100%; height: 100%;"
      @grid-ready="onGridReady"
      :columnDefs="columnDefs"
      :defaultColDef="defaultColDef"
      :masterDetail="true"
      :detailCellRenderer="detailCellRenderer"
      :detailRowHeight="detailRowHeight"
      :groupDefaultExpanded="groupDefaultExpanded"
      :rowData="rowData"
      @first-data-rendered="onFirstDataRendered"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
    DetailCellRenderer,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IAccount> | null>(null);
    const columnDefs = ref<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 = ref<ColDef>({
      flex: 1,
      enableCellChangeFlash: true,
    });
    const detailCellRenderer = ref("DetailCellRenderer");
    const detailRowHeight = ref(70);
    const groupDefaultExpanded = ref(1);
    const rowData = ref<IAccount[]>(null);

    function onFirstDataRendered(params: FirstDataRenderedEvent) {
      setInterval(() => {
        if (!allRowData) {
          return;
        }
        const data = allRowData[0];
        const newCallRecords: any[] = [];
        data.callRecords.forEach((record: any, index: number) => {
          newCallRecords.push({
            name: record.name,
            callId: record.callId,
            duration: record.duration + (index % 2),
            switchCode: record.switchCode,
            direction: record.direction,
            number: record.number,
          });
        });
        data.callRecords = newCallRecords;
        data.calls++;
        const tran = {
          update: [data],
        };
        params.api.applyTransaction(tran);
      }, 2000);
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        allRowData = data;
        params.api!.setGridOption("rowData", allRowData);
      };

      fetch("https://www.ag-grid.com/example-assets/master-detail-data.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      detailCellRenderer,
      detailRowHeight,
      groupDefaultExpanded,
      rowData,
      onGridReady,
      onFirstDataRendered,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Custom Detail with Refresh](https://www.ag-grid.com/examples/master-detail-custom-detail/custom-detail-with-refresh/vue3)

## Keyboard Navigation

To add keyboard navigation to custom detail panels, it must be implemented in the custom Detail Cell Renderer. There are several parts to this:

1. Create a listener function for the `focus` event when the custom detail panel receives focus. Within this function, the event object `target` value is the custom detail row element, and event object `relatedTarget` value is the previous element that was previously focused on. You will need to find the parent of the `relatedTarget` with `role=row` attribute to get the previous row element. With the current row element and the previous row element, checking the `row-index` attribute allows you to see if the user is entering the focus from the previous or current row (ie, `row-index` increases or is the same from previous to current) or the next row (ie, `row-index` decreases from previous to current). With this knowledge, you can set focus using `element.focus()` on the relevant element in your custom detail panel
2. Attach the above function to a `focus` listener on the `eParentOfValue` param value in the component initialisation
3. Remove the above function from the `focus` listener in the component destroy or unmount method

The following example shows an implementation of keyboard navigation in a custom detail panel:

- Click a cell in the `Mila Smith` master row and press `⇥ Tab` key to move focus to the custom detail panel inputs of the `Mila Smith` master row.
- Click a cell in the `Evelyn Taylor` master row and press `⇧ Shift`+`⇥ Tab` to focus the inputs in the custom detail panel of the `Mila Smith` master row.

> **Note**
>
> This example is illustrative of the main concepts, but the actual implementation of custom keyboard navigation will vary based on the specific custom detail panel.

#### Custom Detail Cell Renderer Keyboard Navigation

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  FirstDataRenderedEvent,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  RowApiModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  MasterDetailModule,
} from "ag-grid-enterprise";
import DetailCellRenderer from "./detailCellRendererVue";
import { IAccount } from "./interfaces";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowApiModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  MasterDetailModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <ag-grid-vue
      style="width: 100%; height: 100%;"
      @grid-ready="onGridReady"
      :columnDefs="columnDefs"
      :defaultColDef="defaultColDef"
      :masterDetail="true"
      :detailCellRenderer="detailCellRenderer"
      :detailRowHeight="detailRowHeight"
      :rowData="rowData"
      @first-data-rendered="onFirstDataRendered"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
    DetailCellRenderer,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IAccount> | null>(null);
    const columnDefs = ref<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 = ref<ColDef>({
      flex: 1,
    });
    const detailCellRenderer = ref("DetailCellRenderer");
    const detailRowHeight = ref(70);
    const rowData = ref<IAccount[]>(null);

    function onFirstDataRendered(params: FirstDataRenderedEvent) {
      params.api.forEachNode(function (node) {
        node.setExpanded(node.id === "1");
      });
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/master-detail-data.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      detailCellRenderer,
      detailRowHeight,
      rowData,
      onGridReady,
      onFirstDataRendered,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Custom Detail Cell Renderer Keyboard Navigation](https://www.ag-grid.com/examples/master-detail-custom-detail/custom-detail-keyboard-navigation/vue3)
