Your search did not match any results.

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
@(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.MVC.Demos.Models.SampleData; using System.Text.Json; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class TreeViewController : Controller { public ActionResult LoadDataOnDemand() { return View(); } } }
using System; using System.Linq; using System.Net.Http; using System.Web.Http; using System.Web.Hosting; using System.IO; namespace DevExtreme.MVC.Demos.Controllers.ApiControllers { public class TreeViewDataController : ApiController { [HttpGet] public HttpResponseMessage Get(string parentId) { var rootPath = HostingEnvironment.MapPath("~"); 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 = 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 Request.CreateResponse(childNodes); } } }