DevExtreme React - Enhance Performance on Large Datasets

If the TreeView performance is low, consider enabling the Virtual Mode. In this mode, the TreeView loads a set of child nodes once their parent node is expanded. The Virtual Mode can be enabled only if your data source satisfies the following conditions.

To enable the Virtual Mode, set the virtualModeEnabled option to true.

jQuery
JavaScript
var plainData = [
    { id: 1,  text: 'Fruits',     parentId: -1 },
    { id: 11, text: 'Apples',     parentId: 1, hasItems: false },
    { id: 12, text: 'Oranges',    parentId: 1, hasItems: false },
    { id: 2,  text: 'Vegetables', parentId: -1 },
    { id: 21, text: 'Cucumbers',  parentId: 2, hasItems: false },
    { id: 22, text: 'Tomatoes',   parentId: 2, hasItems: false }
];

$(function() {
    $("#treeViewContainer").dxTreeView({
        dataSource: plainData,
        dataStructure: 'plain',
        virtualModeEnabled: true,
        rootValue: -1
    });
});
Angular
HTML
TypeScript
<dx-tree-view
    [dataSource]="plainData"
    dataStructure="plain"
    [virtualModeEnabled]="true"
    [rootValue]="-1">
</dx-tree-view>
import { DxTreeViewModule } from "devextreme-angular";
// ...
export class AppComponent {
    plainData = [
        { id: 1,  text: 'Fruits',     parentId: -1 },
        { id: 11, text: 'Apples',     parentId: 1, hasItems: false },
        { id: 12, text: 'Oranges',    parentId: 1, hasItems: false },
        { id: 2,  text: 'Vegetables', parentId: -1 },
        { id: 21, text: 'Cucumbers',  parentId: 2, hasItems: false },
        { id: 22, text: 'Tomatoes',   parentId: 2, hasItems: false }
    ];
}
@NgModule({
    imports: [
        // ...
        DxTreeViewModule
    ],
    // ...
})

View Demo

If the Virtual Mode does not meet your requirements, you can get full control over nodes and how to load them in the createChildren function. This function will be called at the beginning of the widget's lifetime and each time a user expands a node whose child nodes have not been loaded yet.

jQuery
JavaScript
$(function() {
    $("#treeViewContainer").dxTreeView({
        createChildren: function (parentNode) {
            var d = $.Deferred();
            $.get("http://url/to/the/service", {
                    parentId: parentNode ? JSON.stringify(parentNode.key) : "0"
                })
                .done(function (result) {
                    d.resolve(result);
                });
            return d.promise();
        },
        dataStructure: 'plain'
    });
});
Angular
HTML
TypeScript
<dx-tree-view
    [createChildren]="createChildren"
    dataStructure="plain">
</dx-tree-view>
import { ..., Inject } from "@angular/core";
import { HttpClient, HttpClientModule, HttpParams } from "@angular/common/http";
import "rxjs/add/operator/toPromise";
import { DxTreeViewModule } from "devextreme-angular";
// ...
export class AppComponent {
    constructor(@Inject(HttpClient) httpClient: HttpClient) { }
    createChildren = (parentNode) => {
        let params: HttpParams = new HttpParams()
            .set("parentId", parentNode ? JSON.stringify(parentNode.key) : "0");
        return httpClient.get("http://url/to/the/service", {
                params: params
            })
            .toPromise();
    }
}
@NgModule({
    imports: [
        // ...
        DxTreeViewModule,
        HttpClientModule
    ],
    // ...
})

View Demo

See Also