Docs

Documentation versions (currently viewingVaadin 25)
Documentation translations (currently viewingEnglish)

Tree Grid

The Tree Grid component displays hierarchical tabular data grouped in expandable nodes.

Tree Grid is a component for displaying hierarchical tabular data grouped into expandable nodes.

Source code
TreeGridBasic.java
Person.java
tree-grid-basic.tsx
tree-grid-basic.ts

Tree Grid is an extension of the Grid component, so it inherits all of Grid’s features, including:

However, Tree Grid isn’t meant to be used as a navigation menu.

Tree Column

The tree column contains the toggles for expanding and collapsing nodes. Nodes are opened and closed by clicking a tree column’s cell. They can also be toggled programmatically.

Source code
TreeGridColumn.java
Person.java
tree-grid-column.tsx
tree-grid-column.ts

Rich Content

Like Grid, Tree Grid supports rich content.

Source code
TreeGridRichContent.java
Person.java
tree-grid-rich-content.tsx
tree-grid-rich-content.ts

Programmatic Scrolling

Tree Grid supports programmatic navigation to a specific item. This is particularly useful when dealing with large data sets. It saves users from having to scroll through potentially hundreds or thousands of rows.

Scrolling to Item By Reference Flow

In Flow, you can bring an item into view by passing its object reference to the scrollToItem(T item) method. This method expands all parent items leading to the specified item and then scrolls the Tree Grid to position that item at the top of the viewport. Scrolling is skipped if the item is already in the viewport and fully visible.

Source code
TreeGridScrollToItem.java

This feature is available out of the box when using TreeDataProvider, a built-in data provider for connecting a TreeData structure to the Tree Grid.

Other data providers must implement two additional methods to support this feature:

  • HierarchicalDataProvider#getParent(T item)

  • HierarchicalDataProvider#getItemIndex(T item, HierarchicalQuery query)

You can find more information about using custom hierarchical data providers on the Data Binding page.

Scrolling to Item by Path

You can also scroll to an item by providing its hierarchical path – an array of indexes where each index refers to a child of the item at the previous index. For example, to scroll to the second child-row (index 1) of the third root-level row (index 2), you would provide the path 2, 1. Scrolling continues until it reaches the last index in the array or encounters a collapsed item.

Source code
TreeGridScrollToIndex.java
tree-grid-scroll-to-index.tsx
tree-grid-scroll-to-index.ts

Drag & Drop

Tree Grid supports drag-and-drop operations. You can enable and handle them in your logic, for example, to allow users to move rows from one parent node to another:

Source code
TreeGridDragDrop.java
tree-grid-drag-drop.tsx
tree-grid-drag-drop.ts

For more drag-and-drop examples and API references, refer to the Grid’s Drag and Drop documentation.

Note

In Flow, Tree Grid drag-and-drop works best with data providers that use the flattened hierarchy format. This format gives more predictable scrolling and allows Tree Grid to maintain its scroll position after hierarchy changes. For more details on this and other supported formats, see the Hierarchy Formats section on the Data Binding page.

Component Usage Recommendation

Grid

Component for showing tabular data.

Grid Pro

Component for showing and editing tabular data.

CRUD

Component for creating, displaying, updating, and deleting tabular data.

9DEF736F-975A-469A-8625-A0A6E086BF50