- Defining minimum and maximum column width
- Touch interaction
Contact Support
Column resizing in EJ2 JavaScript Gantt control
24 Jan 20246 minutes to read
The column width can be resized by clicking and dragging the right edge of the column header. While dragging, the width of the column will be resized immediately. Each column can be auto resized by double-clicking the right edge of the column header to fit the width of that column based on the widest cell content. To resize the column, set the allowResizing
property to true. The following code example shows how to enable the column resize feature in the Gantt control.
To resize the column, inject the Resize
module into the Gantt control.
ej.gantt.Gantt.Inject(ej.gantt.Resize);
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
allowResizing: true,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
splitterSettings:{
columnIndex:4
},
height:'450px'
});
ganttChart.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/29.1.33/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="Gantt"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
You can disable resizing for a particular column by setting the
columns.allowResizing
tofalse
.
Defining minimum and maximum column width
The column resizing can be restricted between minimum and maximum widths by defining the columns->minWidth
and columns->maxWidth
properties.
In the following example, the minimum and maximum widths are defined for the Duration
, and Task Name
columns.
ej.gantt.Gantt.Inject(ej.gantt.Resize);
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
allowResizing: true,
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
splitterSettings:{
columnIndex:5
},
height:'450px',
columns: [
{ field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '100' },
{ field: 'TaskName', headerText: 'Task Name', width: '200',minWidth: '150' ,maxWidth: '250',},
{ field: 'StartDate', headerText: 'Start Date', width: '150' },
{ field: 'Duration', headerText: 'Duration', width: '100',minWidth: '50' ,maxWidth: '200' },
{ field: 'Progress', headerText: 'Progress', width: '150' }
]
});
ganttChart.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/29.1.33/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="Gantt"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Touch interaction
When the right edge of the column header cell is tapped
, a floating handler will be visible over the right border of the column. To resize
the column, drag the floating handler as needed.
The following screenshot represents the Gantt column resizing in touch device.