Column menu in Angular Gantt component

13 May 202424 minutes to read

The column menu in the Syncfusion Angular Gantt chart component provides options to enable features such as sorting, filtering, column chooser, and autofit. When click on the column header’s menu icon, a menu will be displayed with these integrated features. To enable the column menu, you need to set the showColumnMenu property to true in the Gantt configuration.

To use the column menu, inject the ColumnMenuService in the provider section of AppModule.

The default column menu items are displayed in following table.

Item Description
SortAscending Sort the current column in ascending order.
SortDescending Sort the current column in descending order.
AutoFit Autofit the current column.
AutoFitAll Autofit all columns.
ColumnChooser Choose the column visibility.
Filter Show the filter options as given in filterSettings.type
import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data"  [taskFields]="taskSettings" [treeColumnIndex]='1'
         [allowFiltering] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings">    
            <e-columns>
                <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
                <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
                <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
                <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
                <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
            </e-columns>
        </ejs-gantt>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    public data?: object[];
    public taskSettings?: object;
    public splitterSettings?: object;
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

You can disable column menu for a particular column by defining the columns.showColumnMenu as false.

You can customize the default items by defining the columnMenuItems with required items.

Add custom column menu item

The custom column menu item feature allows you to add additional menu items to the column menu in the Syncfusion Gantt chart. These custom menu items can be defined using the columnMenuItems property, which accepts a collection of columnMenuItemModel objects. You can define the actions for these custom items in the columnMenuClick event.

Consider the following example, which demonstrates how to add a custom column menu item to clear the sorting of the gantt:

import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';
import { MenuEventArgs } from '@syncfusion/ej2-navigations';
import { GanttComponent } from '@syncfusion/ej2-angular-gantt';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<ejs-gantt id="ganttDefault" #gantt height="430px" [dataSource]="data"  [taskFields]="taskSettings"  [allowFiltering] = 'true' [treeColumnIndex]='1'
        [allowResizing] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings" [sortSettings]='sortSettings'
       [columnMenuItems]='columnMenuItems' (columnMenuClick)='columnMenuClick($event)'>
        <e-columns>
            <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
            <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
            <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
            <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
            <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
        </e-columns>
       </ejs-gantt>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    @ViewChild('gantt')
    public gantt?: GanttComponent;
    public data?: object[];
    public taskSettings?: object;
    public splitterSettings?: object;
    public columnMenuItems: any = [{ text: 'Clear Sorting', id: 'ganttclearsorting' }];
    public sortSettings: any = { columns: [{ direction: 'Descending', field: 'TaskID' }] };
    public columnMenuClick(args: MenuEventArgs) {
        if (args.item.id === 'ganttclearsorting') {
            this.gantt!.clearSorting();
        }
    }
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

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 property as true in the columnMenuOpen event.

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

import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<ejs-gantt id="ganttDefault" #gantt height="430px" [dataSource]="data"  [taskFields]="taskSettings" [treeColumnIndex]='1' [allowFiltering] = 'true' 
        [allowResizing] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings" 
       (columnMenuOpen)='columnMenuOpen($event)'>
            <e-columns>
                <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
                <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
                <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
                <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
                <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
            </e-columns>
       </ejs-gantt>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    public data?: object[];
    public taskSettings?: object;
    public splitterSettings?: object;
    public columnMenuOpen(args: any) {
        for (const item of args.items) {
            if (item.text === 'Filter' && args.column.field === 'TaskName') {
                (item as any).hide = true;
            } else {
                (item as any).hide = false;
            }
        }
    }
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Render nested column menu

The nested column menu feature provides an extended menu option in the gantt chart column headers, allows you to access additional actions and options related to the columns.

To enable the nested column menu feature, you need to define the columnMenuItems property in your component. The columnMenuItems property is an array that contains the items for the column menu. Each item can be a string representing a built-in menu item or an object defining a custom menu item.

Here is an example of how to configure the columnMenuItems property to include a nested menu:

import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data"  [taskFields]="taskSettings" [treeColumnIndex]='1' [columns]="columns"
         [allowFiltering] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings"
         [columnMenuItems]='columnMenuItems' (columnMenuClick)='columnMenuClick($event)'>
            <e-columns>
                <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
                <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
                <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
                <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
                <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
            </e-columns>
         </ejs-gantt>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    public data?: object[];
    public taskSettings?: object;
    public splitterSettings?: object;
    public columns?: object[];
    public columnMenuItems: object = [
        'SortAscending',
        'SortDescending',
        'Filter',
        {
            text: 'Sub Menu',
            items: [
                { text: 'Option 1', id: 'option1' },
                { text: 'Option 2', id: 'option2' },
                { text: 'Option 3', id: 'option3' },
                {
                    text: 'Nested Sub Menu',
                    items: [
                        { text: 'Nested Option 1', id: 'nestedoption1' },
                        { text: 'Nested Option 2', id: 'nestedoption2' },
                    ],
                },
            ],
        },
    ];
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    }
    public columnMenuClick(args: any) {
        if (args.item.id === 'option1') {
          // custom function
        }
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Customize the icon of column menu

To customize the column menu icon, you need to override the default gantt class .e-icons.e-columnmenu with a custom CSS property called content. By specifying a Unicode character or an icon font’s CSS class, you can change the icon displayed in the column menu.

To customize the column menu icon, follow these steps:

1.Add the necessary CSS code to override the default gantt class:

.e-gantt .e-columnheader .e-icons.e-columnmenu::before {
  content: "\e99a";
}

2.Import the required icon stylesheets. You can use either the material or bootstrap5 style, depending on your preference. Add the following code to import the stylesheets:

<link href="https://cdn.syncfusion.com/ej2/ej2-icons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/ej2-icons/styles/bootstrap5.css" rel="stylesheet" />

Here is an example that demonstrates how to customize the column menu icon in the Syncfusion Gantt chart:

import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data"  [taskFields]="taskSettings" [treeColumnIndex]='1'
         [allowFiltering] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings">
            <e-columns>
                <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
                <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
                <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
                <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
                <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
            </e-columns>
        </ejs-gantt>`,
    styleUrls: ['./app.component.css'],
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    public data?: object[];
    public taskSettings?: object;
    public splitterSettings?: object;
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Column menu events

The column menu in Syncfusion Angular Gantt chart provides a set of events that allow customization of behavior and performing actions when the column menu is opened or clicked. The below events are helpful for adding additional functionality or implementing specific actions based on user interactions with the column menu.

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 chart.

import { BrowserModule } from '@angular/platform-browser';
import { GanttModule, SortService, FilterService, ColumnMenuService } from '@syncfusion/ej2-angular-gantt';

import { Component, ViewEncapsulation, ViewChild, OnInit, NgModule } from '@angular/core';
import { projectNewData } from './data';

@Component({
    imports: [
         GanttModule
    ],
providers: [SortService, FilterService, ColumnMenuService],
standalone: true,
    selector: 'app-root',
    template:
        `<div style="margin-left:180px"><p style="color:red;" id="message"></p></div>
        <ejs-gantt id="ganttDefault" height="430px" [dataSource]="data"  [taskFields]="taskSettings" [treeColumnIndex]='1'
         [allowFiltering] = 'true' [showColumnMenu] = 'true' [allowSorting] = 'true' [splitterSettings]="splitterSettings" 
         (columnMenuOpen)="columnMenuOpen()" (columnMenuClick)="columnMenuClick()">
            <e-columns>
                <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=120 ></e-column>
                <e-column field='TaskName' headerText='Task Name' textAlign='Left' width=290></e-column>
                <e-column field='StartDate' headerText='Start Date' textAlign='Right' width=150 ></e-column>
                <e-column field='Duration' headerText='Duration' textAlign='Right' width=150 ></e-column>
                <e-column field='Progress' headerText='Progress' textAlign='Right' width=150></e-column>
            </e-columns>
        </ejs-gantt>`,
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    // Data for Gantt
    public data?: object[];
    public message?: string;
    public taskSettings?: object;
    public splitterSettings?: object;
    public ngOnInit(): void {
        this.data = projectNewData;
        this.taskSettings = {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
            duration: 'Duration',
            progress: 'Progress',
            child: 'subtasks'
        };
        this.splitterSettings = {
            position: '75%'
        };
    };
    columnMenuOpen() {
        this.message = `columnMenuOpen event is triggered`;
    }
    columnMenuClick() {
        this.message = `columnMenuClick event is triggered`;
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));