Virtual scroll in Vue Gantt component
11 Jun 202422 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
.
<template>
</template>
<script setup>
import { provide } from "vue";
import { GanttComponent as EjsGantt, Selection, VirtualScroll } from "@syncfusion/ej2-vue-gantt";
import{tempData} from "./datasource.js";
var virtualData = [];
var projId = 1;
for (var i = 0; i < 50; i++) {
var x = virtualData.length + 1;
var parent_1 = {};
parent_1['TaskID'] = x;
parent_1['TaskName'] = 'Project' + (projId++);
virtualData.push(parent_1);
for (var j = 0; j < tempData.length; j++) {
var subtasks = {};
subtasks['TaskID'] = tempData[j].TaskID + x;
subtasks['TaskName'] = tempData[j].TaskName;
subtasks['StartDate'] = tempData[j].StartDate;
subtasks['Duration'] = tempData[j].Duration;
subtasks['Progress'] = tempData[j].Progress;
subtasks['parentID'] = tempData[j].parentID + x;
virtualData.push(subtasks);
}
}
new Vue({
el: '#app',
template: `
<div>
<ejs-gantt ref='gantt'
:dataSource= "data"
:taskFields= "taskFields"
:allowSelection= "true"
:enableVirtualization= "true"
:labelSettings= "labelSettings"
:height= "height"
:treeColumnIndex= "1"
:highlightWeekends= "true"
:columns= "columns"
:splitterSettings= "splitterSettings">
</ejs-gantt>
</div>
`,
data: function() {
return{
data : virtualData,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' }
],
height: '450px',
labelSettings: {
taskLabel: 'Progress'
},
splitterSettings: {
columnIndex: 2
}
}
}
,
provide('gantt', [ Selection, VirtualScroll]);
});
</script>
<template>
</template>
<script>
import { GanttComponent, Selection, VirtualScroll } from "@syncfusion/ej2-vue-gantt";
import{tempData} from "./datasource.js";
var virtualData = [];
var projId = 1;
for (var i = 0; i < 50; i++) {
var x = virtualData.length + 1;
var parent_1 = {};
parent_1['TaskID'] = x;
parent_1['TaskName'] = 'Project' + (projId++);
virtualData.push(parent_1);
for (var j = 0; j < tempData.length; j++) {
var subtasks = {};
subtasks['TaskID'] = tempData[j].TaskID + x;
subtasks['TaskName'] = tempData[j].TaskName;
subtasks['StartDate'] = tempData[j].StartDate;
subtasks['Duration'] = tempData[j].Duration;
subtasks['Progress'] = tempData[j].Progress;
subtasks['parentID'] = tempData[j].parentID + x;
virtualData.push(subtasks);
}
}
new Vue({
el: '#app',
template: `
<div>
<ejs-gantt ref='gantt'
:dataSource= "data"
:taskFields= "taskFields"
:allowSelection= "true"
:enableVirtualization= "true"
:labelSettings= "labelSettings"
:height= "height"
:treeColumnIndex= "1"
:highlightWeekends= "true"
:columns= "columns"
:splitterSettings= "splitterSettings">
</ejs-gantt>
</div>
`,
data: function() {
return{
data : virtualData,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' }
],
height: '450px',
labelSettings: {
taskLabel: 'Progress'
},
splitterSettings: {
columnIndex: 2
}
}
}
,
provide: {
gantt: [ Selection, VirtualScroll]
}
});
</script>
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
.
<template>
</template>
<script setup>
import { provide } from "vue";
import { GanttComponent as EjsGantt, Selection, VirtualScroll,Edit } from "@syncfusion/ej2-vue-gantt";
import{tempData} from "./datasource.js";
var virtualData = [];
var projId = 1;
for (var i = 0; i < 50; i++) {
var x = virtualData.length + 1;
var parent_1 = {};
parent_1['TaskID'] = x;
parent_1['TaskName'] = 'Project' + (projId++);
virtualData.push(parent_1);
for (var j = 0; j < tempData.length; j++) {
var subtasks = {};
subtasks['TaskID'] = tempData[j].TaskID + x;
subtasks['TaskName'] = tempData[j].TaskName;
subtasks['StartDate'] = tempData[j].StartDate;
subtasks['Duration'] = tempData[j].Duration;
subtasks['Progress'] = tempData[j].Progress;
subtasks['parentID'] = tempData[j].parentID + x;
virtualData.push(subtasks);
}
}
new Vue({
el: '#app',
template: `
<div>
<ejs-gantt ref='gantt'
:dataSource= "data"
:taskFields= "taskFields"
:allowSelection= "true"
:enableVirtualization= "true"
:labelSettings= "labelSettings"
:height= "height"
:treeColumnIndex= "1"
:highlightWeekends= "true"
:columns= "columns"
:autoCalculateDateScheduling='false',
:editSettings= "editSettings"
:projectStartDate="projectStartDate"
:projectEndDate="projectEndDate"
:enableTimelineVirtualization="true"
:splitterSettings= "splitterSettings">
</ejs-gantt>
</div>
`,
data: function() {
return{
data : virtualData,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' }
],
height: '450px',
labelSettings: {
taskLabel: 'Progress'
},
splitterSettings: {
columnIndex: 2
},
editSettings:{
allowAdding:true
},
projectStartDate: new Date('04/01/2019'),
projectEndDate: new Date('12/31/2025')
}
}
,
provide('gantt', [ Selection, VirtualScroll,Edit]);
});
</script>
<template>
</template>
<script>
import { GanttComponent, Selection, VirtualScroll,Edit } from "@syncfusion/ej2-vue-gantt";
import{tempData} from "./datasource.js";
var virtualData = [];
var projId = 1;
for (var i = 0; i < 50; i++) {
var x = virtualData.length + 1;
var parent_1 = {};
parent_1['TaskID'] = x;
parent_1['TaskName'] = 'Project' + (projId++);
virtualData.push(parent_1);
for (var j = 0; j < tempData.length; j++) {
var subtasks = {};
subtasks['TaskID'] = tempData[j].TaskID + x;
subtasks['TaskName'] = tempData[j].TaskName;
subtasks['StartDate'] = tempData[j].StartDate;
subtasks['Duration'] = tempData[j].Duration;
subtasks['Progress'] = tempData[j].Progress;
subtasks['parentID'] = tempData[j].parentID + x;
virtualData.push(subtasks);
}
}
new Vue({
el: '#app',
template: `
<div>
<ejs-gantt ref='gantt'
:dataSource= "data"
:taskFields= "taskFields"
:allowSelection= "true"
:enableVirtualization= "true"
:labelSettings= "labelSettings"
:height= "height"
:treeColumnIndex= "1"
:highlightWeekends= "true"
:columns= "columns"
:autoCalculateDateScheduling='false',
:editSettings= "editSettings"
:projectStartDate="projectStartDate"
:projectEndDate="projectEndDate"
:enableTimelineVirtualization="true"
:splitterSettings= "splitterSettings">
</ejs-gantt>
</div>
`,
data: function() {
return{
data : virtualData,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'parentID'
},
columns: [
{ field: 'TaskID' },
{ field: 'TaskName' },
{ field: 'StartDate' },
{ field: 'Duration' },
{ field: 'Progress' }
],
height: '450px',
labelSettings: {
taskLabel: 'Progress'
},
splitterSettings: {
columnIndex: 2
},
editSettings:{
allowAdding:true
},
projectStartDate: new Date('04/01/2019'),
projectEndDate: new Date('12/31/2025')
}
}
,
provide: {
gantt: [ Selection, VirtualScroll,Edit]
}
});
</script>
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 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.