DevExtreme Vue - Access a Node

Within Event Handlers

Usually, you need to access a TreeView node when an action was made on it, for example, when it was clicked or selected. This action raises an event, and you can access the node subjected to the action within the event handler.

jQuery
JavaScript
$(function() {
    $("#treeViewContainer").dxTreeView({
        dataSource: data,
        onItemClick: function (e) {
            var node = e.node;
            // ...
        }
    });
});
Angular
HTML
TypeScript
<dx-tree-view
    [dataSource]="data"
    (onItemClick)="onItemClick($event)">
</dx-tree-view>
import { DxTreeViewModule } from 'devextreme-angular';
// ...
export class AppComponent {
    data = [ ... ];
    onItemClick (e) {
        var node = e.node;
        // ...
    }
}
@NgModule({
    imports: [
        // ...
        DxTreeViewModule
    ],
    // ...
})

Not every event handler provides access to the node, only those whose name starts with onItem.... They are described in the TreeView Configuration.

Using a Method

Call the getNodes() method to get TreeView nodes at any point in the application flow.

jQuery
JavaScript
var allNodes = $("#treeViewContainer").dxTreeView("getNodes");
Angular
TypeScript
import { ..., ViewChild } from '@angular/core';
import { DxTreeViewModule, DxTreeViewComponent } from 'devextreme-angular';
// ...
export class AppComponent {
    @ViewChild(DxTreeViewComponent) treeView: DxTreeViewComponent;
    nodeCollection: Array<any> = [];
    getNodes () {
        this.nodeCollection = this.treeView.instance.getNodes();
    }
}
@NgModule({
    imports: [
        // ...
        DxTreeViewModule
    ],
    // ...
})

All node objects contain a similar set of fields, which are described in the Node documentation section.

See Also