The scrollbar will be displayed in the gantt when content exceeds the element width
or height
. The vertical and horizontal scrollbars will be displayed based on the following criteria:
The default value for
height
andwidth
isauto
.
We can even set pixel values to width and height of gantt container using width and height properties.
import { Gantt} from '@syncfusion/ej2-gantt';
import { GanttData } from 'datasource.ts';
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '350px',
width: '600px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks',
},
editSettings: {
allowAdding: true,
allowEditing: true,
allowDeleting: true,
allowTaskbarEditing: true,
showDeleteConfirmDialog: true
},
});
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/21.2.3/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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>
Specify the width and height as 100%
to make the gantt element fill its parent container.
Setting the height
to 100%
requires the gantt parent element to have explicit height. Also, the component will be responsive when the parent container is resized.
import { Gantt} from '@syncfusion/ej2-gantt';
import { GanttData } from 'datasource.ts';
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '100%',
width: '100%',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks',
},
editSettings: {
allowAdding: true,
allowEditing: true,
allowDeleting: true,
allowTaskbarEditing: true,
showDeleteConfirmDialog: true
},
});
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/21.2.3/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>
<style>
.e-ganttresize {
resize: both;
overflow: auto;
border: 1px solid red;
padding: 10px;
height: 300px;
min-height: 250px;
min-width: 250px;
}
.e-text{
font-family: Helvetica, sans-serif;
font-size: 14px;
}
</style>
</head>
<body>
<div id='loader'>Loading....</div>
<p class="e-text"> The parent container can be resizable by dragging the bottom-right corner.</p>
<div id='container' class='e-ganttresize'>
<div id='Gantt'></div>
</div>
</body>
</html>
In the Gantt control, When We use the scrollToDate
method, it will scroll the timeline horizontally to the date that we specified in the method’s argument.
The following code examples show how the scroll To Date method works in Gantt:
import { Gantt, Edit, Selection } from '@syncfusion/ej2-gantt';
import { Button } from '@syncfusion/ej2-buttons';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Edit, Selection);
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
splitterSettings: {
position: "50%"
}
projectStartDate: new Date('04/01/2019'),
projectEndDate: new Date('05/30/2019'),
});
gantt.appendTo('#Gantt');
let scrollBtn: Button = new Button();
scrollBtn.appendTo('#scroll');
document.getElementById('scroll').addEventListener('click', () => {
gantt.scrollToDate('05/27/2019');
});
<!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/21.2.3/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="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<button id="scroll">Scroll To Date</button>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>
In the Gantt control, you can set the vertical scroller position dynamically by clicking the custom button using the setScrollTop
method.
import { Gantt, Edit, Selection } from '@syncfusion/ej2-gantt';
import { Button } from '@syncfusion/ej2-buttons';
import { data } from 'datasource.ts';
Gantt.Inject(Edit, Selection);
let gantt: Gantt = new Gantt({
dataSource: data,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
splitterSettings: {
position: "50%"
}
});
gantt.appendTo('#Gantt');
let scrollBtn: Button = new Button();
scrollBtn.appendTo('#scrollTop');
document.getElementById('scrollTop').addEventListener('click', () => {
gantt.ganttChartModule.scrollObject.setScrollTop(300);
});
<!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/21.2.3/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="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<button id="scrollTop">Change Scroll Position</button>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>