Selection Basics
The Angular TreeList enables the user to select single or multiple cells and rows. It provides a rich API for customizing the selection logic and persisting the selected items based on specific requirements.
Setup
Enable the selection by applying the built-in kendoTreeListSelectable directive.
To configure the selection, use the selectable option. It accepts a boolean or SelectableSettings parameters.
If you use a SelectableSettings parameter, the Kendo UI TreeList for Angular enables you to specify the following options:
mode—Sets the mode of the selection either to"row"or"cell". The default value is"row".multiple—Determines if multiple selection is enabled. The default value isfalse.drag—Configures the drag selection. The default value istrue, but it does not apply unlessmultipleis set totrue.enabled—Determines if the selection functionality is enabled. The default value istrue.checkboxOnly—Determines if the row selection is possible only when the user clicks a checkbox. The default value isfalse.readonly—Determines whether the end user will be able to modify the selection. When the selection functionality is enabled andreadonlyis set totrue, programmatic selection is still possible by using theselectedItemscollection or theisSelectedcallback.
The TreeList selects only the items on the current page. To select all items or persist the selection across pages, refer to the Row Selection and Persisting the Selection articles.
The following example demonstrates the different selection modes and settings for the TreeList component.
The following articles cover common selection scenarios:
Toggling Selection Dynamically
To control the selection state dynamically, bind the selectable option to a component property.
<button (click)="toggleSelection()">Toggle Selection</button>
<kendo-treelist
[data]="data"
[selectable]="isSelectable"
kendoTreeListSelectable>
...
</kendo-treelist>To disable the selection initially while keeping the ability to enable it later, pass a SelectableSettings object with enabled set to false:
<kendo-treelist ...
[selectable]="selectableSettings"
kendoTreeListSelectable
[(selectedItems)]="mySelection">
...
</kendo-treelist>Handling Selection Changes
When the user modifies the selection the TreeList emits a selectionChange event returning a SelectionChangeEvent object. This object contains information about the current selection state, including the selected and deselected items.
Use this event to update external UI elements, calculate totals, enable or disable actions based on the number of selected items, or track user selection behavior.
The following example demonstrates how to handle the selectionChange event to respond to user selection changes.