Your search did not match any results.

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
@(Html.DevExtreme().TreeView() .ID("simple-treeview") .CreateChildren("treeView_createChildren") .RootValue("") .DataStructure(TreeViewDataStructure.Plain) .Height(500) .ExpandNodesRecursive(false) ) <script> function treeView_createChildren(parent) { var parentId = parent ? parent.itemData.id : ""; return $.ajax({ url: "@Url.Content("~/api/TreeViewData")", dataType: "json", data: { parentId: parentId } }); } </script>
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.NETCore.Demos.Models; using DevExtreme.NETCore.Demos.Models.SampleData; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public class TreeViewController : Controller { public ActionResult LoadDataOnDemand() { return View(); } } }
using System; using System.Linq; using System.Net.Http; using System.IO; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Hosting; namespace DevExtreme.NETCore.Demos.Controllers.ApiControllers { [Route("api/[controller]")] public class TreeViewDataController : Controller { IWebHostEnvironment _webHostEnvironment; public TreeViewDataController(IWebHostEnvironment webHostEnvironment) { _webHostEnvironment = webHostEnvironment; } [HttpGet] public object Get(string parentId) { var rootPath = _webHostEnvironment.ContentRootPath; var parentPath = String.IsNullOrEmpty(parentId) ? rootPath : Path.Combine(rootPath, parentId); var childNodes = Directory.EnumerateFileSystemEntries(parentPath) .Where(path => Path.GetFullPath(path).StartsWith(rootPath)) .Select(path => new { id = Path.Combine(parentPath, Path.GetFileName(path)), parentId, text = Path.GetFileName(path), hasItems = System.IO.File.GetAttributes(path).HasFlag(FileAttributes.Directory) }) .Where(i => i.text != "bin" && i.text != "obj" && !i.text.StartsWith(".")) .OrderByDescending(i => i.hasItems) .ThenBy(i => i.text); return childNodes; } } }