Search results

Infinite Scrolling in ASP.NET MVC Tree Grid control

14 Apr 2021 / 2 minutes to read

Infinite scrolling is used to load a huge amount of data without degrading the Tree Grid performance. This feature works like the lazy loading concept, which means the buffer data is loaded only when the scrollbar reaches the end of the scroller.

To use Infinite scrolling, set EnableInfiniteScrolling property as true.

  • In this feature, Tree Grid will not make a new data request when you visit the same page again.
razor
infinitescroll.cs
Copied to clipboard
@Html.EJS().TreeGrid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
    {
        col.Field("TaskID").HeaderText("Player Jersey").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD1").HeaderText("Player Name").Width(120).Add();
        col.Field("FIELD2").HeaderText("Year").Width(100).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD3").HeaderText("Stint").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD4").HeaderText("TMID").Width(120).TextAlign(TextAlign.Right).Add();
    }).Height(400).ChildMapping("Children").TreeColumnIndex(1).EnableInfiniteScrolling().Render()
Copied to clipboard
public IActionResult InfiniteScrolling()
        {
            ViewBag.datasource = VirtualDataFormat.GetVirtualData();
            return View();
        }

InitialBlocks

You can define the initial loading pages count by using InitialBlocks property of InfiniteScrollSettings. By default, this feature loads three pages in initial rendering.

In the below demo, we have changed this property value to load five page records instead of three.

razor
infinitescroll.cs
Copied to clipboard
@Html.EJS().TreeGrid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
    {
        col.Field("TaskID").HeaderText("Player Jersey").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD1").HeaderText("Player Name").Width(120).Add();
        col.Field("FIELD2").HeaderText("Year").Width(100).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD3").HeaderText("Stint").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD4").HeaderText("TMID").Width(120).TextAlign(TextAlign.Right).Add();
    }).Height(400).ChildMapping("Children").TreeColumnIndex(1).EnableInfiniteScrolling().InfiniteScrollSettings(settings => {settings.InitialBlocks(5);}).Render()
Copied to clipboard
public IActionResult InfiniteScrolling()
        {
            ViewBag.datasource = VirtualDataFormat.GetVirtualData();
            return View();
        }

Cache Mode

Cache is used to store the loaded rows object in the Tree Grid instance which can be reused for creating the row elements whenever you scroll to already visited page. Also, this mode maintains row elements based on the MaxBlocks count value of InfiniteScrollSettings, once this limit exceeds then it will remove row elements from DOM for new rows.

To enable the cache mode in Infinite scrolling, set EnableCache property of InfiniteScrollSettings as true.

razor
infinitescroll.cs
Copied to clipboard
@Html.EJS().TreeGrid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
    {
        col.Field("TaskID").HeaderText("Player Jersey").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD1").HeaderText("Player Name").Width(120).Add();
        col.Field("FIELD2").HeaderText("Year").Width(100).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD3").HeaderText("Stint").Width(120).TextAlign(TextAlign.Right).Add();
        col.Field("FIELD4").HeaderText("TMID").Width(120).TextAlign(TextAlign.Right).Add();
    }).Height(400).ChildMapping("Children").TreeColumnIndex(1).EnableInfiniteScrolling(true).InfiniteScrollSettings(settings => {settings.EnableCache(true);}).Render()
Copied to clipboard
public IActionResult InfiniteScrolling()
{
    ViewBag.datasource = VirtualDataFormat.GetVirtualData();
    return View();
}

Limitations for Infinite Scrolling

  • Due to the element height limitation in browsers, the maximum number of records loaded by the tree grid is limited due to the browser capability.
  • Initial loading rows total height must be greater than the viewport height.
  • Cell selection will not be persisted in cache mode.
  • Infinite scrolling is not compatible with batch editing, detail template and hierarchy features.
  • The aggregated information and total group items are displayed based on the current view items. To get these information regardless of the view items, refer to the
  • Programmatic selection using the selectRows and selectRow method is not supported in infinite scrolling.