Virtual scroll in EJ2 TypeScript Gantt control
16 Dec 202315 minutes to read
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
.
import { Gantt, Selection, VirtualScroll } from '@syncfusion/ej2-gantt';
import { virtualData } from 'datasource.ts';
Gantt.Inject(Selection, VirtualScroll);
let gantt: Gantt = new Gantt({
dataSource: virtualData,
treeColumnIndex: 1,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
enableVirtualization: true,
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' },
],
allowSelection: true,
gridLines: 'Both',
height: '450px',
splitterSettings: {
columnIndex: 2
},
labelSettings: {
taskLabel: 'Progress'
}
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</script>
</body>
</html>
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
.
import { Gantt, Selection, VirtualScroll } from '@syncfusion/ej2-gantt';
import { virtualData } from 'datasource.ts';
Gantt.Inject(Selection, VirtualScroll);
let gantt: Gantt = new Gantt({
dataSource: virtualData,
treeColumnIndex: 1,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
enableVirtualization: true,
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' },
],
allowSelection: true,
enableTimelineVirtualization: true,
gridLines: 'Both',
height: '450px',
splitterSettings: {
columnIndex: 2
},
labelSettings: {
taskLabel: 'Progress'
},
projectStartDate: new Date('04/01/2019'),
projectEndDate: new Date('12/31/2025')
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</script>
</body>
</html>
Get filtered data when virtual scrolling is enabled
While enabling virtual scroll you can get the filtered or sorted record count using filteredResult
from the filterModule of the treegrid inside the actionComplete
event.
import { Gantt, Selection, VirtualScroll,Sort,Filter } from '@syncfusion/ej2-gantt';
import { virtualData } from 'datasource.ts';
Gantt.Inject(Selection, VirtualScroll,Sort,Filter);
let filteredCount: any = 0;
let datasetCount: any;
let gantt: Gantt = new Gantt({
dataSource: virtualData,
treeColumnIndex: 1,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
allowSorting: true,
allowFiltering: true,
actionComplete: function (args:any) {
if (args.requestType == 'filtering') {
if (args.rows != null) {
filteredCount =
gantt.treeGrid.filterModule.filteredResult.length;
let combinedMessage = `Dataset Count: ${datasetCount} Filtered Count: ${filteredCount}`;
const countElement = document.getElementById('count-element');
if (countElement) {
countElement.textContent = combinedMessage;
}
}
}
},
created:function() {
datasetCount = gantt.flatData.length;
let combinedMessage = `Dataset Count: ${datasetCount} Filtered Count: ${filteredCount}`;
const countElement = document.getElementById('count-element');
if (countElement) {
countElement.textContent = combinedMessage;
}
},
enableVirtualization: true,
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' },
],
allowSelection: true,
gridLines: 'Both',
height: '450px',
splitterSettings: {
columnIndex: 2
},
labelSettings: {
taskLabel: 'Progress'
}
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
<h1>Counts Display</h1>
<p id="count-element"></p>
</div>
</script>
</body>
</html>
Limitations for virtual vcroll
- Due to the element height limitation in browsers, the maximum number of records loaded is limited by the browser capacity.
- Cell selection will not be persisted.
- The number of records rendered will be determined by the
height
property. - It is necessary to mention the height of the Gantt in pixels when enabling Virtual Scrolling.
- Virtual Scroll does not support Multi Taskbar support in Resource View.