Column menu in gantt control

21 Dec 20228 minutes to read

The column menu has options to integrate features like sorting, filtering, and autofit. It will show a menu with the integrated feature when users click the Multiple icon of the column. To enable the column menu, you should set the ShowColumnMenu property to true. The default items are displayed in the following table:

Item Description
SortAscending Sort the current column in ascending order.
SortDescending Sort the current column in descending order.
AutoFit Auto fit the current column.
AutoFitAll Auto fit all columns.
Filter Show the filter option as given in the filterSettings.type property.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" showColumnMenu="true" allowFiltering="true" allowSorting="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();
}

Alt text

NOTE

You can disable the column menu for a particular column by setting the Columns.ShowColumnMenu to false.

Column menu Events

During the resizing action, the gantt component triggers the below two events.

  1. The columnMenuOpen event triggers before the column menu opens.
  2. The columnMenuClick event triggers when the user clicks the column menu of the gantt.
<ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="550px" gridLines="Both" treeColumnIndex="1"
           allowSorting="true" allowReordering="true" allowFiltering="true" columnMenuOpen="columnMenuOpen" showColumnMenu="true" columnMenuClick="columnMenuClick">
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
                        endDate="EndDate" duration="Duration" progress="Progress" dependency="Predecessor" child="SubTasks">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Name" width="250"></e-gantt-column>
        <e-gantt-column field="Progress"></e-gantt-column>
        <e-gantt-column field="StartDate"></e-gantt-column>
        <e-gantt-column field="Duration"></e-gantt-column>
    </e-gantt-columns>
    <e-gantt-editsettings allowEditing="true"></e-gantt-editsettings>
</ejs-gantt>
<script>
    function columnMenuOpen() {
        alert('columnMenuOpen event is triggered')
    }
    function columnMenuClick() {
        alert('columnMenuClick event is triggered')
    }
</script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}

Custom Column Menu Item

Custom column menu items can be added by defining the columnMenuItems. Actions for this customized items can be defined in the columnMenuClick event.

@{ List<object> columnMenuitems = new List<object>();
    columnMenuitems.Add(new { text = "Clear Sorting", id = "ganttclearsorting" });}
<ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="550px" gridLines="Both" treeColumnIndex="1"
    allowSorting="true" allowReordering="true" allowFiltering="true" columnMenuItems="columnMenuitems" columnMenuClick="columnMenuClick" showColumnMenu="true">
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" endDate="EndDate" duration="Duration" progress="Progress" dependency="Predecessor" child="SubTasks">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Name" width="250"></e-gantt-column>
        <e-gantt-column field="Progress"></e-gantt-column>
        <e-gantt-column field="StartDate"></e-gantt-column>
        <e-gantt-column field="Duration"></e-gantt-column>
    </e-gantt-columns>
    <e-gantt-editsettings allowEditing="true"></e-gantt-editsettings>
</ejs-gantt>
<script>
    function columnMenuClick(args) {
        if (args.item.id === 'ganttclearsorting') {
            this.clearSorting();
        }
    }
</script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}

Customize menu items for particular columns

Sometimes, you have a scenario that to hide an item from column menu for particular columns. In that case, you need to define the columnMenuOpenEventArgs.hide as true in the columnMenuOpen event.

The following sample, Filter item was hidden in column menu when opens for the Task Name column.

<ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="550px" gridLines="Both" treeColumnIndex="1"
           allowSorting="true" allowReordering="true" allowFiltering="true" columnMenuOpen="columnMenuOpen" showColumnMenu="true">
    <e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
                        endDate="EndDate" duration="Duration" progress="Progress" dependency="Predecessor" child="SubTasks">
    </e-gantt-taskfields>
    <e-gantt-columns>
        <e-gantt-column field="TaskId"></e-gantt-column>
        <e-gantt-column field="TaskName" headerText="Name" width="250"></e-gantt-column>
        <e-gantt-column field="Progress"></e-gantt-column>
        <e-gantt-column field="StartDate"></e-gantt-column>
        <e-gantt-column field="Duration"></e-gantt-column>
    </e-gantt-columns>
    <e-gantt-editsettings allowEditing="true"></e-gantt-editsettings>
</ejs-gantt>
<script>
    function columnMenuOpen(args) {
        for (let item of args.items) {
            if (item.text === 'Filter' && args.column.field === 'TaskName') {
                item.hide = true;
            } else {
                item.hide = false;
            }
        }
    }
</script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}