# Persisting the Expanded State

The TreeView enables you to define and persist the expanded state of its nodes when the component is re-rendered.

## Basics

The TreeView exposes the following options to control the expand state:

* `isExpanded` (function)—Determines if a given node is expanded.
* `collapse` (event)—Fired when a given node is about to be collapsed.
* `expand` (event)—Fired when a given node is about to be expanded.

The following example demonstrates how to manually control the expand state of TreeView nodes by implementing the `isExpanded` function and handling the `expand` and `collapse` events.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treeview/fundamentals/expand-state/source.txt)

## Built-in Directives

To persist the expanded state of the TreeView, either:

* [Use the built-in `ExpandDirective`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/expand-state#using-the-built-in-directive), or
* [Set an item field](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/expand-state#setting-an-item-field).

### Using the Built-In Directive

By default, the built-in [`ExpandDirective`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/expanddirective) persists the expanded items based on their hierarchical index.

> The TreeView renders the expand icons only after the `children` and `hasChildren` functions are defined.

The following example demonstrates how to use the built-in `ExpandDirective` to automatically persist the expanded state of TreeView nodes by their hierarchical index.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treeview/default-expand-state/source.txt)

### Setting an Item Field

You can also persist the expanded state of the TreeView by item field—for example, the `id` field.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treeview/expand-state-by-id/source.txt)

## Expand Disabled Nodes

The component can be configured to allow exapnding disabled nodes by setting the [`expandDisabledNodes`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/treeviewcomponent#expanddisablednodes) option to `true`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treeview/expand-disabled-nodes/source.txt)

## Suggested Links

* [Angular TreeView Homepage](https://www.telerik.com/kendo-angular-ui/treeview)
* [API Reference of the Angular TreeView](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api)
