Maximize Performance with Load-on-Demand and Virtualization Features in Essential JS 2 TreeGrid
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Maximize Performance with Load-on-Demand and Virtualization Features in Essential JS 2 TreeGrid

Maximize Performance with Load-on-Demand and Virtualization Features in Essential JS 2 TreeGrid

The Syncfusion Essential JS 2 TreeGrid component is a versatile and powerful tool for displaying hierarchical data in a structured, easy-to-navigate format. In addition to being available in JavaScript, the TreeGrid component can be used in the ASP.NET (CoreMVC), React, Angular, and Vue frameworks.

Tree grids are a great way to represent hierarchical data in a tabular format, but they might become slow and unwieldy when dealing with large data sets. This is where the load-on-demand and virtualization features come in handy.

The load-on-demand feature allows you to load records from remote services only when they are requested by the user, instead of loading all records at once. Virtualization renders the row elements for the current viewport only and other row elements while scrolling in the TreeGrid.

These features are beneficial when dealing with large data sets that can cause performance issues if they are all loaded at once.

Let’s see how the load-on-demand and virtualization features enhance performance and the user experience while handling a huge volume of data in the Essential JS 2 TreeGrid.

How to enable load-on-demand and virtualization features in the TreeGrid

Note: This guide is based on the Syncfusion ASP.NET Core Tree Grid component. If you are new to this platform, please visit the getting started page before proceeding.

Component-side configurations

We’ll use the data manager to provide the data source from a remote URL.

Refer to the following code example.

<ejs-treegrid id="TreeGrid" 
idMapping="TaskID"
parentIdMapping="ParentValue"
loadChildOnDemand="true"
hasChildMapping="isParent"
treeColumnIndex="1"
enableVirtualization="true"
height="400"> <e-data-manager url="/Home/DataSource"
adaptor="UrlAdaptor"
e-data-manager> … </ejs-treegrid>

In this code example:

  • idMapping and parentIdMapping—These properties connect self-referential data from remote services in parent-child relationships.
  • HasChildMapping—This property represents the data objects in the data source, indicating whether the current record is a parent record. The TreeGrid can’t identify the records that have child records when data is loaded on-demand.
  • LoadChildOnDemand—This property is optional. It loads all the parent records in an expanded state with their child records when enabled. In this blog, we will enable this property.
  • EnableVirtualization—Enable this property to load only the records needed for the current viewport. The remaining data will be loaded on demand while scrolling. Without this property, the TreeGrid will load all the parent records simultaneously, thus affecting the performance.

These configurations are needed on the component side to enable load-on-demand and virtualization features in the TreeGrid.

Note: The paging feature loads all the child records at once. Thus, it affects performance. But the virtual scrolling feature loads only the child records necessary for the current viewport and dynamically loads other records during vertical scrolling.

Server-side remote service configurations

For every action, like scrolling to the next record set or expanding the parent records, the TreeGrid will request the server return the next data set. So, these requests must be handled in the remote service, and it will return the required data based on the request.

The requests from the TreeGrid component are sent to the DataManagerRequest as parameters. The data operations will be performed and returned to the client TreeGrid component based on the parameters.

Refer to the following code example with inline comments.

public IActionResult DataSource([FromBody] DataManagerRequest dm)
{
   List<TreeData> data = new List<TreeData>();
   data = TreeData.GetTree();
   DataOperations operation = new DataOperations();
   IEnumerable<TreeData> DataSource = data;
 
   if (!(dm.Where != null && dm.Where.Count > 1))
   {
      data = data.Where(p => p.ParentValue == null).ToList(); //filter root parent records for further easy data operations
 
   }
   DataSource = data;
   if (dm.Where != null && dm.Where.Count > 1)
   {
      DataSource = operation.PerformFiltering(DataSource, dm.Where, "and");
   }
   data = new List<TreeData>();
   foreach (var rec in DataSource)
   {
      data.Add(rec as TreeData);
   }
 
   // Filter parent and child records for the current viewport
   var GroupData = TreeData.GetTree().ToList().GroupBy(rec => rec.ParentValue).Where(g => g.Key != null).ToDictionary(g => g.Key?.ToString(), g => g.ToList());
   foreach (var Record in data.ToList())
   {
       if (GroupData.ContainsKey(Record.TaskID.ToString()))
       {
          var ChildGroup = GroupData[Record.TaskID.ToString()];
          if (ChildGroup?.Count > 0)
             AppendChildren(dm, ChildGroup, Record, GroupData, data);
       }
    }
    DataSource = data;
 
    if (dm.Expand != null && dm.Expand[0] == "CollapsingAction") // setting the skip index based on collapsed parent
     {
        string IdMapping = "TaskID";
        List<WhereFilter> CollapseFilter = new List<WhereFilter>();
        CollapseFilter.Add(new WhereFilter() { Field = IdMapping, value = dm.Where[0].value, Operator = dm.Where[0].Operator });
        var CollapsedParentRecord = operation.PerformFiltering(DataSource, CollapseFilter, "and");
        var index = data.Cast<object>().ToList().IndexOf(CollapsedParentRecord.Cast<object>().ToList()[0]);
        dm.Skip = index;
     }
     else if (dm.Expand != null && dm.Expand[0] == "ExpandingAction") // setting the skip index based on expanded parent
     {
        string IdMapping = "TaskID";
        List<WhereFilter> ExpandFilter = new List<WhereFilter>();
        ExpandFilter.Add(new WhereFilter() { Field = IdMapping, value = dm.Where[0].value, Operator = dm.Where[0].Operator });
        var ExpandedParentRecord = operation.PerformFiltering(DataSource, ExpandFilter, "and");
        var index = data.Cast<object>().ToList().IndexOf(ExpandedParentRecord.Cast<object>().ToList()[0]);
        dm.Skip = index;
     }
     int count = data.Count;
     DataSource = data;
 
     //Paging operation
     if (dm.Skip != 0)
     {
        DataSource = operation.PerformSkip(DataSource, dm.Skip);  
     }
     if (dm.Take != 0)
     {
        DataSource = operation.PerformTake(DataSource, dm.Take);
     }
     return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
 
}

Performance metrics

Let’s compare the performance metrics for rendering 10,000 records with and without load-on-demand and virtualization features in the TreeGrid.

Without virtualization (normal scrolling) and loading data at once using data binding

With virtualization and load-on-demand data binding

~12 seconds

~800 milliseconds

From this table data, it is evident that with load-on-demand and virtualization, the performance of the TreeGrid can be drastically enhanced.

GitHub reference

Check out the complete code example for Load-on-demand and virtualization features in the Essential JS 2 TreeGrid on GitHub.

Conclusion

Thanks for reading! In this blog, we’ve seen how the load-on-demand and virtualization features help us to enhance performance and the user experience in the Essential JS 2 TreeGrid. Please visit the TreeGrid’s online demos and documentation for more information. We appreciate your feedback, which you can leave in the comments section below.

You can download our free trial if you do not have a Syncfusion license but wish to try the TreeGrid component.

For questions, you can contact us via our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed