Virtual Scrolling in ASP.NET MVC Gantt Chart
Virtual Scroll support in Gantt allows you to load large amount of data without performance degradation. To enable Virtual Scrolling, you need to inject VirtualScroll module in Gantt.
Row virtualization
Row virtualization allows you to load and render a large number of tasks in Gantt with effective performance. In this mode, all tasks are fetched initially from the datasource and rendered in the DOM within a compact viewport area.
The number of records displayed in the Gantt is determined by the height.
This mode can be enable by setting the EnableVirtualization property to true.
@(Html.EJS().Gantt("VirtualScroll").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").EnableVirtualization(true).HighlightWeekends(true).AllowSelection(true)
.TaskFields(ts => ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress")
.Child("SubTasks").ParentID("ParentID"))
.LabelSettings(ls=>ls.TaskLabel("Progress")).Columns(col =>
{
col.Field("TaskId").Width(140).Add();
col.Field("TaskName").Width(250).Add();
col.Field("StartDate").Add();
col.Field("EndDate").Add();
col.Field("Duration").Add();
col.Field("Progress").Add();
}).SplitterSettings(ss => ss.ColumnIndex(2))
.Render()
)public IActionResult Index()
{
ViewBag.dataSource = GanttData.VirtualData();
return View();
}
Configure dom virtualization
Dom virtualization improves scrolling performance when a Gantt chart contains many tasks. Rather than keeping every task row in the dom at once, it renders the rows in the viewport along with a buffer of nearby rows. Limiting the number of rendered row elements reduces dom workload and helps scrolling remain smooth.
Enable dom virtualization
Set EnableDomVirtualization to true in the Gantt configuration to enable dom virtualization. Use DomVirtualizationSettings.RowBuffer to configure the number of additional rows rendered around the visible rows. The default RowBuffer value is 20.
The following example enables dom virtualization for a large dataset:
@(Html.EJS().Gantt("VirtualScroll").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").EnableDomVirtualization(true).HighlightWeekends(true).AllowSelection(true)
.TaskFields(ts => ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress")
.Child("SubTasks").ParentID("ParentID"))
.LabelSettings(ls=>ls.TaskLabel("Progress")).Columns(col =>
{
col.Field("TaskId").Width(140).Add();
col.Field("TaskName").Width(250).Add();
col.Field("StartDate").Add();
col.Field("EndDate").Add();
col.Field("Duration").Add();
col.Field("Progress").Add();
}).SplitterSettings(ss => ss.ColumnIndex(2))
.Render()
)public IActionResult Index()
{
ViewBag.dataSource = GanttData.VirtualData();
return View();
}
Timeline virtualization
Timeline virtualization allows you to load a data source having large timespan with high performance. Initially, it renders the timeline with thrice the width of the gantt element, while other timeline cells render on-demand during horizontal scrolling.
This mode can be enable by setting the EnableTimelineVirtualization property to true.
@(Html.EJS().Gantt("VirtualScroll").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").EnableVirtualization(true).EnableTimelineVirtualization(true).HighlightWeekends(true).AllowSelection(true)
.TaskFields(ts => ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress")
.Child("SubTasks").ParentID("ParentID"))
.LabelSettings(ls=>ls.TaskLabel("Progress")) .EditSettings(es => es.AllowAdding(true).AllowEditing(true).AllowDeleting(true).AllowTaskbarEditing(true).ShowDeleteConfirmDialog(true))
.AutoCalculateDateScheduling(false).Toolbar(new List<string>() { "Add", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll", "Indent", "Outdent" }).Columns(col =>
{
col.Field("TaskId").Width(140).Add();
col.Field("TaskName").Width(250).Add();
col.Field("StartDate").Add();
col.Field("EndDate").Add();
col.Field("Duration").Add();
col.Field("Progress").Add();
}).SplitterSettings(ss => ss.ColumnIndex(2))
.Render()
)public IActionResult Index()
{
ViewBag.dataSource = GanttData.VirtualData();
return View();
}Limitations for virtual scroll
- Due to the element height limitation in browsers, the maximum number of records loaded is limited by the browser capacity.
- Cell-based selection is not supported when virtualization is enabled.
- The number of records rendered will be determined by the
Heightproperty. - It is necessary to mention the height of the Gantt in pixels when enabling Virtual Scrolling.