Column reordering in gantt control
21 Dec 20224 minutes to read
The column reordering can be done by dragging a column header from one index to another index within the TreeGrid. To enable reordering, set the AllowReordering property to true.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" allowReordering="true">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}NOTE
You can disable the reordering of a particular column by setting the
Columns.AllowReorderingproperty tofalse.
Reorder Events
During the reorder action, the gantt component triggers the below three events.
- The
columnDragStartevent triggers when column header element drag (move) starts. - The
columnDragevent triggers when column header element is dragged (moved) continuously. - The
columnDropevent triggers when a column header element is dropped on the target column.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" allowReordering="true" columnDragStart="columnDragStart"
columnDrag="columnDrag" columnDrop="columnDrop">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
</ejs-gantt>
<script>
function columnDragStart() {
alert('columnDragStart event is triggered');
}
function columnDrag() {
alert('columnDrag event is triggered');
}
function columnDrop() {
alert('columnDrop event is triggered');
}
</script>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}Reorder multiple columns
Multiple columns can be reordered at a time by using the reorderColumns method.
<ejs-button id="reorderMultipleCols" content="Reorder Task ID and Task Name to Last" cssClass="e-primary"></ejs-button>
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" allowReordering="true">
<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('reorderMultipleCols').addEventListener('click', function (args) {
var ganttObj = document.getElementById('Gantt').ej2_instances[0];
ganttObj.reorderColumns(['TaskId', 'TaskName'], 'Progress');
});
</script>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}