Scrolling in Gantt Control

21 Dec 20226 minutes to read

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 vertical scrollbar appears when the total height of rows present in the gantt exceeds its element height.
  • The horizontal scrollbar appears when the sum of columns width exceeds the grid pane size.
  • The height and width are used to set the gantt height and width, respectively.

NOTE

The default value for height and width is auto.

Set width and height

To specify the width and height of the scroller in the pixel, set the pixel value to a number.

The following code example shows how to set height and width in the Gantt control:

<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" width="600px">
        <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
            endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
        </e-gantt-taskfields>
        <e-gantt-editsettings allowAdding="true" allowEditing="true" allowDeleting="true">
        </e-gantt-editsettings>
    </ejs-gantt>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.EditingData();	
    return View();
}

Responsive with the parent container

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.

The following code example shows how to set height and width in the Gantt control:

<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="100%" width="100%">
        <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
            endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
        </e-gantt-taskfields>
        <e-gantt-editsettings allowAdding="true" allowEditing="true" allowDeleting="true">
        </e-gantt-editsettings>
    </ejs-gantt>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.EditingData();	
    return View();
}

Scroll To Date method

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:

<ejs-button id="scrollToDate" content="Change Scroll Position" cssClass="e-primary"></ejs-button>
                <ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="450px">
                    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
                          endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
                    </e-gantt-taskfields>
                </ejs-gantt>
				
	<script>
        document.getElementById('scrollToDate').addEventListener('click', function (args) {
            var ganttObj = document.getElementById('Gantt').ej2_instances[0];
            ganttObj.scrollToDate('05/20/2019');
        });
    </script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}

Set the vertical scroll position

In the Gantt control, you can set the vertical scroller position dynamically by clicking the custom button using the setScrollTop method.

<ejs-button id="setScrollTop" content="Change Scroll Position" cssClass="e-primary"></ejs-button>
                <ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="450px">
                    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
                          endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
                    </e-gantt-taskfields>
                </ejs-gantt>
				
	<script>
        document.getElementById('setScrollTop').addEventListener('click', function (args) {
            var ganttObj = document.getElementById('Gantt').ej2_instances[0];
            ganttObj.ganttChartModule.scrollObject.setScrollTop(300);
        });
    </script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}