# Custom Selection

The [Angular TreeList](https://www.telerik.com/kendo-angular-ui/components/treelist) provides low-level hooks for implementing custom selection logic.

## Setting the Selected Rows

You can set the selected rows by specifying the [`isSelected`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#isselected) function. The function is executed for each data row in the TreeList and determines whether the row will be selected.

> The built-in [`kendoTreeListSelectable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/selectabledirective) directive applies its own `isSelected` callback to determine which rows or cells will be selected. To override the default behavior, do not apply the directive when using a custom `isSelected` callback. To refresh the selected state and force re-evaluation of the `isSelected` callback, invoke the [`updateView`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#updateview) method.

The following example demonstrates row selection with the `isSelected` callback.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/selection/is-selected-row/source.txt)

## Setting the Selected Cells

To set the selected cells programmatically, specify the [`isSelected`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#isselected) function. The function is executed for each data cell in the TreeList and determines whether the cell will be selected based on the `dataItem` and `columnIndex` values.

The following example demonstrates cell selection with the `isSelected` callback.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/selection/is-selected-cell/source.txt)

## Persisting Selection in Data Items

You can persist the selected state of rows in the TreeList by using the `isSelected` callback together with the [`selectionChange`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#selectionchange) event.

The following example demonstrates how to maintain the selected state as a field on the data item.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/selection/custom-selection/source.txt)

## Disabling the Selection of Specific Elements

The TreeList automatically handles clicks made on non-focusable elements and performs selection. To disable this default behavior for custom or specific non-focusable elements, apply the `k-treelist-ignore-click` class.

```html
<ng-template kendoTreeListCellTemplate let-dataItem>
  <div class="k-treelist-ignore-click">
    Ignored Element
  </div>
  {{ dataItem.name }}
</ng-template>
```

The following example prevents the row selection when clicking on the custom element displayed inside the cell.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/selection/ignore-click/source.txt)

## Suggested Links

* [`SelectableDirective`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/selectabledirective)
* [`isSelected`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#isselected)
* [API Reference of the `TreeListComponent`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent)
* [API Index of the TreeList](https://www.telerik.com/kendo-angular-ui/components/treelist/api)
