# Controlling the Expanded State

The [Angular Grid](https://www.telerik.com/kendo-angular-ui/components/grid) enables you to define and persist the expanded state of its master-detail rows.

## Built-in Directive

The Grid provides a built-in directive to simplify controlling the expanded state of a master-detail row.

The [kendoGridExpandDetailsBy](https://www.telerik.com/kendo-angular-ui/components/grid/api/expanddetailsdirective) directive automatically handles the [detailCollapse](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent#detailcollapse) and [detailExpand](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent#detailexpand) events and provides the [isDetailExpanded](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent#isdetailexpanded) function to the Grid.

The directive takes the key name or a function that returns the key value for a given data item as argument. The item key will be stored in the [expandedDetailKeys](https://www.telerik.com/kendo-angular-ui/components/grid/api/expanddetailsdirective#expandeddetailkeys) collection.This approach provides you with full control over the expanded details functionality—for example, it allows you to specify initially expanded items, manually update the collection, and so on.

The following example demonstrates using the directive.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/master-detail/expanded-state/expanded-directive/source.txt)

## Providing a Callback

The Grid exposes the [isDetailExpanded](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent#isdetailexpanded) function to control
and determines if a specific master-detail row is expanded.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/master-detail/expanded-state/source.txt)

## Suggested Links

* [DetailTemplateDirective](https://www.telerik.com/kendo-angular-ui/components/grid/api/detailtemplatedirective)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent)
* [API Index of the Grid](https://www.telerik.com/kendo-angular-ui/components/grid/api)
