Column Resizing in ASP.NET Core Gantt Chart

The ASP.NET Core Gantt Chart enables dynamic column resizing by dragging column header edges. This feature enhances readability and layout flexibility, especially when working with large datasets. To enable this feature, set the allowResizing property to true in the Gantt configuration.

Column width can be adjusted by dragging the right edge of the header, with changes applied immediately.

@page
@model IndexModel

<div style="margin-top: 20px;">
<ejs-gantt id='Gantt' height="430px" allowResizing="true" dataSource="@Model.GanttDataSourceCollection" treeColumnIndex="1">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
</div>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

Column resize

  • You can disable resizing for a particular column, by specifying columns.allowResizing to false.
  • In RTL mode, you can click and drag the left edge of header cell to resize the column.
  • The width property of the column can be set initially to define the default width of the column. However, when column resizing is enabled, you can override the default width by manually resizing the columns.

Restrict the resizing based on minimum and maximum width

The Gantt chart control allows restricting column resizing within a defined range to maintain layout consistency. This ensures column widths remain within the specified limits during resizing.

To enable this, set the columns.minWidth and columns.maxWidth properties in the column configuration.

The following example demonstrates how the TaskID column can be configured with a minimum width of 100 pixels and a maximum of 200 pixels, while the TaskName column can be set between 150 and 300 pixels.

@page
@model IndexModel

<div style="margin-top: 20px;">
<ejs-gantt id='Gantt' height="430px" allowResizing="true" dataSource="@Model.GanttDataSourceCollection" treeColumnIndex="1">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" textAlign="Right" width="90" minWidth="100" maxWidth="200"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290" minWidth="150" maxWidth="300"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
</div>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

column resizing minimum and maximum width

Prevent resizing for particular column

You can prevent resizing for a specific column in the Gantt Chart control to maintain a consistent column width. To disable resizing, set the allowResizing property of the respective column to false.

The following example demonstrates how to disable resizing for the TaskID column.

@page
@model IndexModel

<div style="margin-top: 20px;">
<ejs-gantt id='Gantt' height="430px" allowResizing="true" dataSource="@Model.GanttDataSourceCollection" treeColumnIndex="1">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" allowResizing="false" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
</div>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

Prevent resizing

You can also prevent resizing by setting args.cancel to true in the resizeStart event.

Column resizing modes

The ASP.NET Core Gantt Chart control supports two resizing modes that determine how column widths behave during resizing. These modes are configured using the resizeSettings.mode property (values: ‘Normal’ ‘Auto’) of the underlying TreeGrid during the component’s load event or through direct property assignment.

Available resizing modes:

  1. Normal mode (mode: 'Normal'): Columns retain their defined widths. If the total column width is less than the Gantt width, empty space appears to the right. If it exceeds, a horizontal scrollbar is shown.
  2. Auto mode (mode: 'Auto'): Columns automatically expand or contract to fill the available space based on the Gantt width.

To apply a resizing mode, set the resizeSettings.mode property on the treeGrid object within the Gantt instance. This can be done during the load event or dynamically based on user interaction.

The following example demonstrates how to set the resizeSettings.mode to Normal or Auto based on the change event of the DropDownList control.

@page
@model IndexModel

<div style="display: flex; align-items: center; margin-bottom: 10px;">
    <label style="padding-right: 10px;font-weight:bold">Change the resize mode:</label>
    <ejs-dropdownlist style="margin-top: 5px;" id="mode" index="0" width="150" dataSource="@Model.ModeData" change="valueChange">
    </ejs-dropdownlist>
</div>
<ejs-gantt id='Gantt' height="430px" allowResizing="true" dataSource="@Model.GanttDataSourceCollection" treeColumnIndex="1">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
<script>
    function valueChange(args) {
        var gantt = document.getElementById("Gantt").ej2_instances[0];
        gantt.treeGrid.grid.resizeSettings.mode = args.value;
    }
</script>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public List<object> ModeData { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
            ModeData = new List<object>()
            {
                new { text = "Normal", value = "Normal" },
                new { text = "Auto", value = "Auto" }
            };
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

Column resizing modes

When the autoFit property of the treeGrid object in the Gantt instance is set to true, the Gantt will automatically adjust its column width based on the content inside them. In normal resize mode, if the autoFit property is set to true, the Gantt will maintain any empty space that is left over after resizing the columns. However, in auto resize mode, the Gantt will ignore any empty space.

Resize columns programmatically

You can programmatically resize columns in the Gantt Chart control by accessing the target column using the getColumnByField method and updating its width property. This is useful for implementing custom UI controls or dynamic layout adjustments. To reflect the change, call the refreshColumns method from the treeGrid object within the Gantt instance.

The following example demonstrates how to resize a column externally using the change event of the DropDownList control.

@page
@model IndexModel

<div style="display: flex; align-items: center; margin-bottom: 15px;">
    <label style="padding-right: 10px;font-weight:bold">Change the field:</label>
    <ejs-dropdownlist style="margin-top: 5px;" id="value" index="0" width="120" dataSource="@Model.FieldData">
    </ejs-dropdownlist>
</div>
<div style="margin-bottom: 20px;">
    <label style="padding-right: 10px;font-weight:bold">Enter the width:</label>
    <input id="textbox" class="e-input" type="text" placeholder="Enter new width" style="width:120px" />
    <button id="button" class="e-btn" onclick="onExternalResize()">Resize</button>
</div>
<div style="margin-top: 20px;">
<ejs-gantt id='Gantt' height="430px" dataSource="@Model.GanttDataSourceCollection" treeColumnIndex="1">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
</div>
<script>
    document.getElementById('button').addEventListener('click', onExternalResize);
    function onExternalResize() {
        var gantt = document.getElementById("Gantt").ej2_instances[0];
        var dropInstance = document.getElementById("value").ej2_instances[0];
        var field = dropInstance.value;
        var newWidth = document.getElementById('textbox').value;
        if (field && newWidth && gantt) {
            var column = gantt.treeGrid.getColumnByField(field);
            if (column) {
                column.width = newWidth;
                gantt.treeGrid.refreshColumns();
            }
        }
    }
</script>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public List<object> FieldData { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
            FieldData = new List<object>()
            {
                new { text = "TaskId", value = "TaskId" },
                new { text = "TaskName", value = "TaskName" },
                new { text = "StartDate", value = "StartDate" },
                new { text = "Duration", value = "Duration" }
            };
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

Column resizing programmatically

The refreshColumns method of the treeGrid object in the Gantt instance is used to refresh the Gantt after the column widths are updated. Column resizing externally is useful when you want to provide a custom interface to the user for resizing columns.

Customize column resizing behavior using events

You can control column resizing using the resizeStart, resizing, and resizeStop events. Each event fires at a different stage of the resize operation, allowing you to customize behavior for different columns.

The following example demonstrates how to handle each resizing event separately in their respective event handlers:

  • resizeStart event handler: Cancels resizing for the TaskID column by setting args.cancel = true.
  • resizing event handler: Prevents width changes for the Duration column during the resize operation.
  • resizeStop event handler: Applies custom CSS styles to the TaskName column after resizing completes.
@page
@model IndexModel

<div style="margin-left: 180px;">
    <p style="color: red;" id="message"></p>
</div>
<ejs-gantt id='Gantt' height="430px" dataSource="@Model.GanttDataSourceCollection" allowResizing="true" resizeStart="resizeStart" resizing="resizing" resizeStop="resizeStop">
    <e-gantt-splittersettings position="75%"></e-gantt-splittersettings>
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentId="ParentId">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-gantt-column>
        <e-gantt-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-gantt-column>
        <e-gantt-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-gantt-column>
        <e-gantt-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-gantt-column>
    </e-gantt-columns>
</ejs-gantt>
<style>
    .e-gantt .e-headercell.customcss, .e-gantt .e-rowcell.customcss {
        background-color: rgb(43, 195, 226);
    }
</style>
<script>
    function resizeStart(args) {
        var field = args.column.field;
        document.getElementById('message').textContent = 'resizeStart event triggered and cancelled for ' + field;
        if (field === 'TaskId') {
            args.cancel = true;
        }
    }

    function resizing(args) {
        var field = args.column.field;
        document.getElementById('message').textContent = 'resizing event triggered and cancelled for ' + field;
        if (field === 'Duration') {
            args.cancel = true;
        }
    }

    function resizeStop(args) {
        document.getElementById('message').textContent = 'resizeStop event triggered';
        var gantt = document.getElementById("Gantt").ej2_instances[0];
        var field = args.column.field;
        var index = args.column.index;
        var headerCell = gantt.treeGrid.getColumnHeaderByField(field);
        if (headerCell) {
            headerCell.classList.add('customcss');
        }
        var columnCells = gantt.treeGrid.getContentTable().querySelectorAll('[data-colindex="' + index + '"]');
        for (var i = 0; i < columnCells.length; i++) {
            columnCells[i].style.backgroundColor = 'rgb(43, 195, 226)';
        }
    }
</script>
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CoreSamples.Pages
{
    public class IndexModel : PageModel
    {
        public List<GanttDataSource> GanttDataSourceCollection { get; set; }

        public void OnGet()
        {
            GanttDataSourceCollection = GetTaskCollection();
        }

        private List<GanttDataSource> GetTaskCollection()
        {
            return new List<GanttDataSource>()
            {
                new GanttDataSource
                {
                    TaskId = 1,
                    TaskName = "Project Initiation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 2,
                    TaskName = "Identify Site location",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 3,
                    TaskName = "Perform Soil test",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 4,
                    TaskName = "Soil test approval",
                    StartDate = new DateTime(2019, 4, 2),
                    Duration = 4,
                    Progress = 50,
                    ParentId = 1
                },
                new GanttDataSource
                {
                    TaskId = 5,
                    TaskName = "Project Estimation",
                    StartDate = new DateTime(2019, 4, 2),
                    EndDate = new DateTime(2019, 4, 21)
                },
                new GanttDataSource
                {
                    TaskId = 6,
                    TaskName = "Develop floor plan for estimation",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 7,
                    TaskName = "List materials",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                },
                new GanttDataSource
                {
                    TaskId = 8,
                    TaskName = "Estimation approval",
                    StartDate = new DateTime(2019, 4, 4),
                    Duration = 3,
                    Progress = 50,
                    ParentId = 5
                }
            };
        }
    }

    public class GanttDataSource
    {
        public int TaskId { get; set; }

        public string TaskName { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? Duration { get; set; }

        public int? Progress { get; set; }

        public int? ParentId { get; set; }
    }
}

Column resizing events

The ResizeArgs object passed to the events contains information such as the current column width, new column width, column index, and the original event. The resizing event is triggered multiple times during a single resize operation, so be careful when performing heavy operations in this event.

Touch interaction

The Gantt Chart control automatically supports touch interactions for mobile devices when allowResizing is enabled.

Resizing columns on touch devices:

To resize a column on a touch-enabled device:

  1. Tap and hold on the right edge of the column header to activate the resize mode.
  2. A floating handler appears over the column border, indicating the resize is active.
  3. Drag the handler left or right to adjust the column width.
  4. Release your finger to apply the new width.

Note: Touch resizing works the same as desktop drag-and-drop. The column menu’s AutoFit option is also available on touch devices for quick width adjustments.

The screenshot below illustrates column resizing on a touch device.

Column resizing touch interaction