TreeView
The TreeView widget is a tree-like representation of textual data.
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
$(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
<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
<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
<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
@(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) )
See Also
Events
This section describes events fired by this widget.
See Also
- Handle Events: jQuery | Angular | AngularJS | Knockout | ASP.NET MVC
Node
A TreeView node.
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.
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.