# Virtual Scrolling

The Kendo UI for Angular TreeList supports virtual scrolling as an alternative to paging. Virtual scrolling renders only the rows currently visible in the viewport, regardless of the total data size. As the user scrolls, the TreeList calculates which rows to display based on the scroll position, the fixed `rowHeight`, and the configured `pageSize`, swapping rows in and out of the DOM to maintain a smooth experience with large datasets.

Virtual scrolling in the TreeList requires the following settings:

* (Required) [`scrollable`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#scrollable)—Set to `virtual`.
* (Required) [`height`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#height)—Sets the height of the TreeList.
* (Required) [`rowHeight`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#rowheight)—Must match the actual height of each TreeList row (`tr`) element in the DOM. The value is used for internal calculations and does not directly set the row height.
* (Required) [`pageSize`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#pagesize)—To avoid unexpected behavior during scrolling, set `pageSize` to at least three times the number of visible rows. The number of visible rows is determined by the `height` and `rowHeight` settings.
* (Required) Data source—Provide data through one of the following:
  * The [`data`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#data) property combined with the [`fetchChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#fetchchildren) and [`hasChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#haschildren) callbacks. Use this approach when you manage the tree structure manually or load data from a remote source.
  * The [`kendoTreeListHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/hierarchybindingdirective) or [`kendoTreeListFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/flatbindingdirective) directive. These directives handle in-memory data operations automatically and are the recommended approach for local data.

Depending on your scenario, see the following sections for configuration and examples:

| Section                                                                                                                                                                      | Description                                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Virtualization with Local Data](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/scroll-modes/virtual#virtualization-with-local-data)                   | Use `kendoTreeListHierarchyBinding` or `kendoTreeListFlatBinding` for fast, in-memory operations when all data is available on the client.        |
| [Virtualization with Manual Data Binding](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/scroll-modes/virtual#virtualization-with-manual-data-binding) | Use the `data` property with `fetchChildren` and `hasChildren` callbacks for manual tree structure control or when not using a binding directive. |
| [Virtualization with Remote Data](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/scroll-modes/virtual#virtualization-with-remote-data)                 | Bind the TreeList to remote sources, handle `pageChange` events, and display loading indicators for large-data experiences.                       |
| [Virtualization with Aggregates](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/scroll-modes/virtual#virtualization-with-aggregates)                   | Combine virtual scrolling with aggregated hierarchical data using the binding directives.                                                         |
| [Virtualization with Responsive Columns](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/scroll-modes/virtual#virtualization-with-responsive-columns)   | Maintain consistent row heights while using responsive columns that adapt to the viewport width.                                                  |

## Virtualization with Local Data

To bind the TreeList to local data with virtual scrolling, use the [`kendoTreeListHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/hierarchybindingdirective) or [`kendoTreeListFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/flatbindingdirective) directive. The directive handles in-memory data operations and the TreeList calculates which rows to display based on the `pageSize` and scroll position.

The following example demonstrates virtual scrolling with local data.

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

## Virtualization with Manual Data Binding

Use manual data binding when you need more control over the tree structure, such as when loading data from a remote source, implementing custom logic for determining parent-child relationships, or managing data that doesn't fit a standard hierarchical format.

Instead of using a binding directive, you can provide data directly through the [`data`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#data) property and control the tree structure with two callbacks:

* [`fetchChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#fetchchildren)—Returns the child nodes for a given parent item.
* [`hasChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#haschildren)—Determines whether a given item has child nodes.

When you use `fetchChildren`, the TreeList maintains an internal flat list of all expanded nodes and renders only the `pageSize` rows that fall within the current viewport. Virtualization is active regardless of whether the [`pageChange`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#pagechange) event is handled.

<TabStrip>
<TabStripTab title="Hierarchical Data">

Pass the array of root items to `data` and return each item's children array in `fetchChildren`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/scrolling/virtual-data-hierarchical/source.txt)

</TabStripTab>
<TabStripTab title="Flat Data">

Build a `parentId`-to-children map before binding. Pass the root items (those with no parent) to `data` and use the map inside `fetchChildren` and `hasChildren`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/scrolling/virtual-data-flat/source.txt)

</TabStripTab>
</TabStrip>

## Virtualization with Remote Data

To use virtualization with remote data, bind the [`data`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#data) property to a remote source. Implement the [`fetchChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#fetchchildren) event handler to fetch new data from the server as the user expands nodes.

The following example demonstrates virtual scrolling with remote data.

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

## Virtualization with Aggregates

You can use virtual scrolling in combination with aggregates by using the [`kendoTreeListFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/flatbindingdirective) or [`kendoTreeListHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/hierarchybindingdirective) directive. The directives support only in-memory data processing, so you must provide the full dataset.

The following example demonstrates virtual scrolling with aggregated hierarchical data.

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

## Virtualization with Responsive Columns

The virtual scrolling functionality requires that all TreeList rows have an equal, predefined height. However, you can still use responsive columns that show or hide based on the viewport width by setting the [`media`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/columncomponent#media) property on each column.

The following example demonstrates virtual scrolling with responsive columns.

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

## Known Limitations

The TreeList's virtual scrolling may be affected by browser-specific limitations in terms of the maximum height of the container element. Values higher than the browser's limit cannot ensure reliable vertical scrolling and the scrollbar's thumb may seem immovable.

## Suggested Links

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