Search results

Getting Started

This section briefly explains about how to include a TreeView in your Blazor client-side application. You can refer Getting Started with Syncfusion Blazor for Client-Side in Visual Studio 2019 Preview page for the introduction and configuring the common specifications.

Importing Syncfusion Blazor component in the application

  1. Install Syncfusion.EJ2.Blazor NuGet package to the application by using the NuGet Package Manager. Please ensure to check the Include prerelease option
  2. You can add the client-side resources through CDN or local npm package in the <head> element of the ~/wwwroot/index.html page.
<head>
    <link href="https://cdn.syncfusion.com/ej2/17.3.29/material.css" rel="stylesheet" />
    <script src="https://cdn.syncfusion.com/ej2/17.3.29/dist/ej2.min.js"></script>
</head>

Adding component package to the application

Open ~/_Imports.razor file and import the Syncfusion.EJ2.Blazor.Navigations packages.

    @using Syncfusion.EJ2.Blazor
    @using Syncfusion.EJ2.Blazor.Navigations

Adding TreeView component to the application

Now, add the Syncfusion Blazor TreeView component in any web page razor in the Pages folder. For example, the TreeView component is added in the ~/Pages/Index.razor page.

@using Syncfusion.EJ2.Blazor.Navigations
<EjsTreeView TValue="MailItem">
 <TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="FolderName" ParentID="ParentId" HasChildren="HasSubFolders" Expanded="Expanded"></TreeViewFieldsSettings>
</EjsTreeView>

@code{
 public class MailItem
 {
     public string Id { get; set; }
     public string ParentId { get; set; }
     public string FolderName { get; set; }
     public bool Expanded { get; set; }
     public bool HasSubFolders { get; set; }
 }
 List<MailItem> MyFolder = new List<MailItem>();
 protected override void OnInitialized()
 {
     base.OnInitialized();
     MyFolder.Add(new MailItem
     {
         Id = "1",
         FolderName = "Inbox",
         HasSubFolders = true,
         Expanded = true
     });
     MyFolder.Add(new MailItem
     {
         Id = "2",
         ParentId = "1",
         FolderName = "Categories",
         Expanded = true,
         HasSubFolders = true
     });
     MyFolder.Add(new MailItem
     {
         Id = "3",
         ParentId = "2",
         FolderName = "Primary"
     });
     MyFolder.Add(new MailItem
     {
         Id = "4",
         ParentId = "2",
         FolderName = "Social"
     });
     MyFolder.Add(new MailItem
     {
         Id = "5",
         ParentId = "2",
         FolderName = "Promotions"
     });
 }
}

Run the application

After successful compilation of your application, simply press F5 to run the application.

TreeView Sample

See Also