Search results

Infinite Scrolling in ASP.NET Core Tree Grid control

20 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.
tagHelper
infinitescroll.cs
Copied to clipboard
<ejs-treegrid id="TreeGrid" height="600" dataSource="ViewBag.datasource" enableInfiniteScrolling="true"  childMapping="Children" treeColumnIndex="1">
    <e-treegrid-pagesettings pageSize="50"></e-treegrid-pagesettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskID" headerText="Player Jersey" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD1" headerText="Player Name" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD2" headerText="Year" textAlign="Right" width="100"></e-treegrid-column>
        <e-treegrid-column field="FIELD3" headerText="Stint" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD4" headerText="TMID" textAlign="Right" width="120"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
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 e-treegrid-infinitescrollsettings tag helper. 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.

tagHelper
infinitescroll.cs
Copied to clipboard
<ejs-treegrid id="TreeGrid" height="600" dataSource="ViewBag.datasource" enableInfiniteScrolling="true" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-infinitescrollsettings initialBlocks="5"></e-treegrid-infinitescrollsettings>
    <e-treegrid-pagesettings pageSize="50"></e-treegrid-pagesettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskID" headerText="Player Jersey" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD1" headerText="Player Name" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD2" headerText="Year" textAlign="Right" width="100"></e-treegrid-column>
        <e-treegrid-column field="FIELD3" headerText="Stint" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD4" headerText="TMID" textAlign="Right" width="120"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
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 e-treegrid-infinitescrollsettings tag helper, 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 e-treegrid-infinitescrollsettings tag helper as true.

tagHelper
infinitescroll.cs
Copied to clipboard
<ejs-treegrid id="TreeGrid" height="600" dataSource="ViewBag.datasource" enableInfiniteScrolling="true"  childMapping="Children" treeColumnIndex="1">
    <e-treegrid-infinitescrollsettings enableCache="true"></e-treegrid-infinitescrollsettings>
    <e-treegrid-pagesettings pageSize="50"></e-treegrid-pagesettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskID" headerText="Player Jersey" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD1" headerText="Player Name" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD2" headerText="Year" textAlign="Right" width="100"></e-treegrid-column>
        <e-treegrid-column field="FIELD3" headerText="Stint" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="FIELD4" headerText="TMID" textAlign="Right" width="120"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
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.