Tree Grid Virtualization
2 Jan 20244 minutes to read
TreeGrid allows you to load large amount of data without performance degradation.
Row Virtualization
Row virtualization allows you to load and render rows only in the content viewport. It is an alternative way of paging in which the rows will be appended while scrolling vertically. To setup the row virtualization, you need to define EnableVirtualization
as true and content height by Height
property.
The number of records displayed in the TreeGrid is determined implicitly by height of the content area and a buffer records will be maintained in the TreeGrid content in addition to the original set of rows.
Expand and Collapse state of any child record will be persisted.
@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).EnableVirtualization(true).Render()
public IActionResult VirtualScrolling()
{
ViewBag.datasource = VirtualDataFormat.GetVirtualData();
return View();
}
Column Virtualization
Column virtualization allows you to virtualize columns. It will render column only in the current view port and all other columns are rendered on demand during horizontal scrolling.
To setup the column virtualization, set the EnableVirtualization
and EnableColumnVirtualization
properties as true
.
@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();
col.Field("Field6").HeaderText("GP").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field7").HeaderText("GS").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field8").HeaderText("Minutes").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field9").HeaderText("Points").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field10").HeaderText("oRebounds").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field11").HeaderText("dRebounds").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field12").HeaderText("Rebounds").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field13").HeaderText("Assists").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field14").HeaderText("Steals").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field15").HeaderText("Blocks").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field16").HeaderText("Turnovers").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field17").HeaderText("PF").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field18").HeaderText("fgAttempted").Width("150").TextAlign(TextAlign.Right).Add();
col.Field("Field19").HeaderText("fgMade").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field20").HeaderText("ftAttempted").Width("150").TextAlign(TextAlign.Right).Add();
col.Field("Field21").HeaderText("ftMade").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field22").HeaderText("ThreeAttempted").Width("150").TextAlign(TextAlign.Right).Add();
col.Field("Field23").HeaderText("ThreeMade").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field24").HeaderText("PostGP").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field25").HeaderText("PostGS").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field26").HeaderText("PostMinutes").Width("120").TextAlign(TextAlign.Right).Add();
col.Field("Field27").HeaderText("PostPoints").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field28").HeaderText("PostoRebounds").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field29").HeaderText("PostdRebounds").Width("130").TextAlign(TextAlign.Right).Add();
col.Field("Field30").HeaderText("PostRebounds").Width("130").TextAlign(TextAlign.Right).Add();
}).Height(400).ChildMapping("Children").TreeColumnIndex(1).EnableVirtualization(true).EnableColumnVirtualization(true).Render()
public IActionResult VirtualScrolling()
{
ViewBag.datasource = VirtualDataFormat.GetVirtualData();
return View();
}
NOTE
Column’s
Width
is required for column virtualization. If column’s width is not defined then tree grid will consider its value as200px
.
Limitations for Virtualization
- Due to the element height limitation in browsers, the maximum number of records loaded by the treegrid is limited by the browser capability.
- Cell selection will not be persisted in row.
- Virtual scrolling is not compatible with detail template, clipboard functionality and row drag and drop features.
- The page size provided must be two times larger than the number of visible rows in the TreeGrid. If the page size is failed to meet this condition then the size will be determined by TreeGrid.
- The virtual height of the treegrid content is calculated using the row height and total number of records in the data source and hence features which changes row height such as text wrapping are not supported. If you want to increase the row height to accommodate the content then you can specify the row height as below to ensure all the table rows are in same height.
.e-treegrid .e-row {
height: 2em;
}
- Programmatic selection using the SelectRows method is not supported in virtual scrolling.
- When virtualization is active in a tree grid, the editCell method is unusable for records outside the currently visible viewport.
NOTE
You can refer to our
ASP.NET MVC Tree Grid
feature tour page for its groundbreaking feature representations. You can also explore ourASP.NET MVC Tree Grid example
to knows how to present and manipulate data.