DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Tree View - Load Data on Demand

You can use the createChildren function to specify custom logic to load data. This function is called each time a user expands a node that was not expanded before. The node's identifier is passed to the function as an argument. Send this identifier to the data service that should return data for child nodes.

As an alternative, you can enable virtual mode to use the default load logic.

Backend API
<dx-tree-view id="simple-treeview" [createChildren]="createChildren" dataStructure="plain" rootValue="" [expandNodesRecursive]="false" [height]="500" > </dx-tree-view>
import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; import { HttpClient, provideHttpClient, withFetch } from '@angular/common/http'; import { lastValueFrom } from 'rxjs'; import { DxTreeViewComponent, DxTreeViewModule } from 'devextreme-angular'; if (!/localhost/.test(document.location.host)) { enableProdMode(); } @Component({ styleUrls: [`app/app.component.css`], selector: 'demo-app', templateUrl: './app.component.html', providers: [], imports: [DxTreeViewModule], }) export class AppComponent { createChildren: DxTreeViewComponent['createChildren']; constructor(http: HttpClient) { this.createChildren = (parent: Record<string, { id: unknown }>) => { const parentId = parent ? parent.itemData.id : ''; return lastValueFrom( http.get(`https://js.devexpress.com/Demos/NetCore/api/TreeViewData?parentId=${parentId}`), ); }; } } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), provideHttpClient(withFetch()), ], });
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> <script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script> <script src="./bundle.js" type="module"></script> </body> </html>