Selection

The TreeView allows the user to select a single node or multiple nodes.

Setup

To enable the selection, apply the built-in SelectDirective directive. It accepts the kendoTreeViewSelectable property, which enables you to control the built-in selection behavior, and both boolean and SelectableSettings parameters.

If you use a SelectableSettings parameter, the TreeView enables you to specify the following options:

  • enabledDetermines if the selection is initially enabled. The default value is true.
  • modeSets the SelectionMode of the selection. The default value is single.
Example
View Source
Edit In Stackblitz  
Change Theme:

Modes

The SelectDirective provides the default TreeView implementation for the single selection mode and the multiple selection mode of items.

Single Selection Mode

By default, the SelectDirective persists the selected item by utilizing its hierarchical index. To select a specific TreeView item by its hierarchical index, use the selectedKeys property.

Example
View Source
Edit In Stackblitz  
Change Theme:

You can also persist the single selection state by an item fieldfor example, an id field. To select a specific TreeView item by its unique id field, use the selectedKeys property.

Example
View Source
Edit In Stackblitz  
Change Theme:

Multiple Selection Mode

To enable the multiple selection mode, use the kendoTreeViewSelectable property which sets the mode field to multiple.

By default, the SelectDirective persists the selected items by their hierarchical index. To display initially selected TreeView items, use the selectedKeys property and pass a list of hierarchical indices.

Example
View Source
Edit In Stackblitz  
Change Theme:

Similar to the single selection mode, you can also persist the multiple selection state by an item fieldfor example, an id field. To select TreeView items by their unique id fields, use the selectedKeys property and pass a list of the selected ids.

Example
View Source
Edit In Stackblitz  
Change Theme:

Modifying the Selection

When the user modifies the selection, the TreeView emits the selectionChange event. It contains the following information:

  • indexThe index of the affected TreeView item.
  • dataItemThe data item of the selected TreeView item.

You can also render a specific item as selected by collecting the provided information and using the isSelected property.

Example
View Source
Edit In Stackblitz  
Change Theme:

In this article

Not finding the help you need?