This example binds our DevExpress Blazor TreeView to a data source and uses the DxTreeViewDataMapping component to load child nodes on demand.
-
Install the Microsoft.EntityFrameworkCore.Proxies NuGet package and call the
UseLazyLoadingProxies
method to enable lazy load functionality.builder.Services.AddDbContextFactory<NorthwindContext>((sp, options) => { var env = sp.GetRequiredService<IWebHostEnvironment>(); var dbPath = Path.Combine(env.ContentRootPath, "Northwind.db"); options .UseLazyLoadingProxies() .UseSqlite("Data Source=" + dbPath); });
-
Set the DxTreeview.LoadChildNodesOnDemand property to
true
to activate lazy data loading inDxTreeView
. -
Add a DxTreeViewDataMapping component and use its HasChildren property to indicate whether a node has child nodes. If true, the node displays an expand glyph even if its children are not yet loaded from the data source.
<DxTreeView Data="@Data" LoadChildNodesOnDemand="true"> <DataMappings> <DxTreeViewDataMapping Text="@(nameof(Category.CategoryName))" Children="@(nameof(Category.Products))" HasChildren="@(nameof(Category.HasProducts))" > </DxTreeViewDataMapping> <DxTreeViewDataMapping Level="1" Text="ProductName"/> </DataMappings> </DxTreeView>