TreeView

The TreeView widget is a tree-like representation of textual data.

Included in: dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/tree_view
Export: default
TreeView interactive configuration
Copy Code
Copy to Codepen
$("#treeview").dxTreeView({
});

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the TreeView widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
$(function () {
    $("#treeView").dxTreeView({
        dataSource: [
            { id: "1", text: "Item 1" },
            { id: "1_1", text: "Subitem 1.1", parentId: "1" },
            { id: "1_2", text: "Subitem 1.2", parentId: "1" },
            { id: "2", text: "Item 2" },
            { id: "2_1", text: "Subitem 2.1", parentId: "2" },
            { id: "2_2", text: "Subitem 2.2", parentId: "2" }
        ],
        dataStructure: 'plain'
    });
});
<div id="treeView"></div>
Angular
HTML
TypeScript
<dx-tree-view
    [dataSource]="treeViewDataSource"
    dataStructure="plain">
</dx-tree-view>
import { DxTreeViewModule } from 'devextreme-angular'
// ...
export class AppComponent {
    treeViewDataSource = [
        { id: "1", text: "Item 1" },
        { id: "1_1", text: "Subitem 1.1", parentId: "1" },
        { id: "1_2", text: "Subitem 1.2", parentId: "1" },
        { id: "2", text: "Item 2" },
        { id: "2_1", text: "Subitem 2.1", parentId: "2" },
        { id: "2_2", text: "Subitem 2.2", parentId: "2" }
    ];
}
@NgModule({
    imports: [
        // ...
        DxTreeViewModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-tree-view="{
        dataSource: treeViewDataSource,
        dataStructure: 'plain'
    }"></div>
</div>
angular.module('DemoApp', ['dx'])
    .controller("DemoController", function ($scope) {
        $scope.treeViewDataSource = [
            { id: "1", text: "Item 1" },
            { id: "1_1", text: "Subitem 1.1", parentId: "1" },
            { id: "1_2", text: "Subitem 1.2", parentId: "1" },
            { id: "2", text: "Item 2" },
            { id: "2_1", text: "Subitem 2.1", parentId: "2" },
            { id: "2_2", text: "Subitem 2.2", parentId: "2" }
        ];
    });
Knockout
HTML
JavaScript
<div data-bind="dxTreeView: {
    dataSource: treeViewDataSource,
    dataStructure: 'plain'
}"></div>
var viewModel = {
    treeViewDataSource: [
        { id: "1", text: "Item 1" },
        { id: "1_1", text: "Subitem 1.1", parentId: "1" },
        { id: "1_2", text: "Subitem 1.2", parentId: "1" },
        { id: "2", text: "Item 2" },
        { id: "2_1", text: "Subitem 2.1", parentId: "2" },
        { id: "2_2", text: "Subitem 2.2", parentId: "2" }
    ]
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().TreeView()
    .ID("treeView")
    .DataSource(new object[] {
        new { id = "1", text = "Item 1" },
        new { id = "1_1", text = "Subitem 1.1", parentId = "1" },
        new { id = "1_2", text = "Subitem 1.2", parentId = "1" },
        new { id = "2", text = "Item 2" },
        new { id = "2_1", text = "Subitem 2.1", parentId = "2" },
        new { id = "2_2", text = "Subitem 2.2", parentId = "2" }
    })
    .DataStructure(TreeViewDataStructure.Plain)
)
@(Html.DevExtreme().TreeView() _
    .ID("treeView") _
    .DataSource({
        New With { .id = "1", .text = "Item 1" },
        New With { .id = "1_1", .text = "Subitem 1.1", .parentId = "1" },
        New With { .id = "1_2", .text = "Subitem 1.2", .parentId = "1" },
        New With { .id = "2", .text = "Item 2" },
        New With { .id = "2_1", .text = "Subitem 2.1", .parentId = "1" },
        New With { .id = "2_2", .text = "Subitem 2.2", .parentId = "1" }
    }) _
    .DataStructure(TreeViewDataStructure.Plain)
)
NOTE
The TreeView widget requires each data source item to contain at least a key field. Thus, the widget does not support data sources consisting of value items.

View Demo Watch Video

See Also
Show Example:
AngularJS
Knockout
jQuery

Configuration

An object defining configuration options for the TreeView widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events fired by this widget.

See Also

Node

A TreeView node.

Type:

Object

This section describes the contents of a TreeView node object. Such objects can be accessed using the getNodes() method and within functions handling the events whose name begins with item....

See Also

Default Item Template

This section lists the data source fields that are used in a default item template.

Type:

Object

By default, a predefined item template is applied to display the items of this widget. This template is based on certain fields of the data source provided for this widget. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom item template based on these or other fields of your data source.

See Also