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({
});

                    

You can create the widget using one of the following approaches.

jQuery
JavaScript
HTML
var species = [
    { id: 1, parentId: 0, text: "Species" },
    { id: 2, parentId: 1, text: "Cat" },
    { id: 3, parentId: 1, text: "Dog" },
    { id: 4, parentId: 1, text: "Cow" },
    { id: 5, parentId: 2, text: "Abyssinian" },
    { id: 6, parentId: 2, text: "Aegean cat" },
    { id: 7, parentId: 2, text: "Australian Mist" },
    { id: 8, parentId: 3, text: "Affenpinscher" },
    { id: 9, parentId: 3, text: "Afghan Hound" },
    { id: 10, parentId: 3, text: "Airedale Terrier" },
    { id: 11, parentId: 3, text: "Akita Inu" },
    { id: 12, parentId: 0, text: "Birds" },
    { id: 13, parentId: 12, text: "Akekee" },
    { id: 14, parentId: 12, text: "Arizona Woodpecker" },
    { id: 15, parentId: 12, text: "Black-chinned Sparrow" }
];
$(function () {
    $("#treeView").dxTreeView({
        dataSource: species,
        dataStructure: 'plain'
    });
});
<div id="treeView"></div>
Angular
HTML
TypeScript
<dx-tree-view
    [dataSource]="species"
    dataStructure="plain">
</dx-tree-view>
export class AppComponent {
    species = [
        // ...   
    ];
}
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-tree-view="{
        dataSource: species,
        dataStructure: 'plain'
    }"></div>
</div>
angular.module('DemoApp', ['dx'])
    .controller("DemoController", function ($scope) {
        $scope.species = [
            // ...   
        ];
    });
Knockout
HTML
JavaScript
<div data-bind="dxTreeView: {
    dataSource: species,
    dataStructure: 'plain'
}"></div>
var viewModel = {
    species: [
        // ...
    ]
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().TreeView()
    .ID("treeView")
    .DataSource(Species)
    .DataStructure(TreeViewDataStructure.Plain)
)
@(Html.DevExtreme().TreeView() _
    .ID("treeView") _
    .DataSource(Species) _
    .DataStructure(TreeViewDataStructure.Plain)
)

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the topics in the Installation section.

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

Configuration

An object defining configuration options for the TreeView widget.

Name Description
accessKey

Specifies the shortcut key that sets focus on the widget.

activeStateEnabled

Specifies whether or not the widget changes its state when interacting with a user.

animationEnabled

Specifies whether or not to animate item collapsing and expanding.

createChildren

Allows you to load nodes manually.

dataSource

A data source used to fetch data to be displayed by the widget.

dataStructure

Specifies whether a nested or plain array is used as a data source.

disabled

Specifies whether the widget responds to user interaction.

disabledExpr

Specifies the name of the data source item field whose value defines whether or not the corresponding widget item is disabled.

displayExpr

Specifies the name of the data source item field whose value is displayed by the widget.

elementAttr

Specifies the attributes to be attached to the widget's root element.

expandAllEnabled

Specifies whether or not a user can expand all tree view items by the "*" hot key.

expandedExpr

Specifies the name of the data source item field whose value defines whether or not the corresponding widget item is displayed expanded.

expandNodesRecursive

Specifies whether or not all parent nodes of an initially expanded node are displayed expanded.

focusStateEnabled

Specifies whether the widget can be focused using keyboard navigation.

hasItemsExpr

Specifies the name of the data source item field whose value defines whether or not the corresponding node includes child nodes.

height

Specifies the widget's height.

hint

Specifies text for a hint that appears when a user pauses on the widget.

hoverStateEnabled

Specifies whether the widget changes its state when a user pauses on it.

itemHoldTimeout

The time period in milliseconds before the onItemHold event is raised.

items

An array of items displayed by the widget.

itemsExpr

Specifies the name of the data source item field that contains an array of nested items.

itemTemplate

Specifies a custom template for an item.

keyExpr

Specifies which data field provides keys for TreeView items.

noDataText

The text or HTML markup displayed by the widget if the item collection is empty.

onContentReady

A handler for the contentReady event. Executed when the widget's content is ready. This handler may be executed multiple times during the widget's lifetime depending on the number of times its content changes.

onDisposing

A handler for the disposing event. Executed when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

onInitialized

A handler for the initialized event. Executed only once, after the widget is initialized.

onItemClick

A handler for the itemClick event.

onItemCollapsed

A handler for the itemCollapsed event.

onItemContextMenu

A handler for the itemContextMenu event.

onItemExpanded

A handler for the itemExpanded event.

onItemHold

A handler for the itemHold event.

onItemRendered

A handler for the itemRendered event.

onItemSelectionChanged

A handler for the itemSelectionChanged event.

onOptionChanged

A handler for the optionChanged event. Executed after an option of the widget is changed.

onSelectionChanged

A handler for the selectionChanged event. Raised after an item is selected or unselected.

parentIdExpr

Specifies the name of the data source item field for holding the parent key of the corresponding node.

rootValue

Specifies the parent ID value of the root item.

rtlEnabled

Switches the widget to a right-to-left representation.

scrollDirection

A string value specifying available scrolling directions.

searchValue

Specifies the current value used to filter tree view items.

selectAllText

Specifies the text displayed at the "Select All" check box.

selectByClick

Specifies whether or not an item becomes selected if a user clicks it.

selectedExpr

Specifies the name of the data source item field whose value defines whether or not the corresponding widget items is selected.

selectionMode

Specifies item selection mode.

selectNodesRecursive

Specifies whether or not to select nodes recursively.

showCheckBoxesMode

Specifies the current check boxes display mode.

tabIndex

Specifies the number of the element when the Tab key is used for navigating.

virtualModeEnabled

Specifies if the virtual mode is enabled.

visible

Specifies whether the widget is visible.

width

Specifies the widget's width.

Methods

This section describes members used to manipulate the widget.

Name Description
beginUpdate()

Prevents the widget from refreshing until the endUpdate() method is called.

collapseItem(itemData)

Collapses an item found using a key.

collapseItem(itemElement)

Collapses an item found using an HTML element.

collapseItem(key)

Collapses an item found using a key.

defaultOptions(rule)

Specifies the device-dependent default configuration options for this component.

element()

Gets the root element of the widget.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

expandItem(itemData)

Expands an item found using a data object.

expandItem(itemElement)

Expands an item found using an HTML element.

expandItem(key)

Expands an item found using a key.

focus()

Sets focus on the widget.

getDataSource()

Gets the DataSource instance.

getNodes()

Returns all nodes of the tree view.

instance()

Returns this widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Gets the widget's options.

option(optionName)

Gets a specific option value.

option(optionName, optionValue)

Assigns a new value to a specific option.

option(options)

Sets one or more options.

registerKeyHandler(key, handler)

Registers a handler to be executed when a user presses a specific key.

repaint()

Repaints the widget. Call it if you made modifications that changed the widget's state to invalid.

selectAll()

Selects all widget items.

selectItem(itemData)

Selects an item found using a data object.

selectItem(itemElement)

Selects an item found using an HTML element.

selectItem(key)

Selects an item found using a key.

unselectAll()

Unselects all widget items.

unselectItem(itemData)

Clears the selection of an item found using a data object.

unselectItem(itemElement)

Clears the selection of an item found using an HTML element.

unselectItem(key)

Clears the selection of an item found using a key.

updateDimensions()

Updates the tree view scrollbars according to the current size of the widget content.

Events

This section describes events fired by this widget.

Name Description
contentReady

Raised when the widget's content is ready.

disposing

Raised when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

initialized

Raised only once, after the widget is initialized.

itemClick

Fires when a widget item is clicked.

itemCollapsed

Fires when a tree view item is collapsed.

itemContextMenu

Fires when the right mouse button is clicked when the pointer is over a widget item, or when the "sustained" (also known as a long press) touch action is performed.

itemExpanded

Fires when a tree view item is expanded.

itemHold

Fires when the widget's collection item is being held for the time period specified by the itemHoldTimeout option.

itemRendered

Fires after a collection item is rendered.

itemSelectionChanged

Fires when a tree view item is selected.

optionChanged

Raised after an option of the widget is changed.

selectionChanged

Fires after a collection item is selected or unselected.

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