Column menu in React Gantt component
2 Feb 202324 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. |
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Sort, Filter, Resize, ColumnMenu } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
return <GanttComponent dataSource={data} taskFields={taskFields}
allowSorting={true} allowFiltering={true} allowResizing={true} showColumnMenu = {true} height = '450px'>
<Inject services={[Sort, Filter, Resize, ColumnMenu]} />
</GanttComponent>
};
ReactDOM.render(<App />, document.getElementById('root'));
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Sort, Filter, Resize, ColumnMenu } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
return <GanttComponent dataSource={data} taskFields={taskFields}
allowSorting={true} allowFiltering={true} allowResizing={true} showColumnMenu = {true} height = '450px'>
<Inject services={[Sort, Filter, Resize, ColumnMenu]} />
</GanttComponent>
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
You can disable column menu for a particular column by defining the
columns.showColumnMenu
asfalse
.
Column menu Events
During the resizing action, the gantt component triggers the below two events.
- The
columnMenuOpen
event triggers before the column menu opens. - The
columnMenuClick
event triggers when the user clicks the column menu of the gantt.
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Sort, Filter, ColumnMenu } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const splitterSettings = {
columnIndex : 5
};
function columnMenuOpen(){
alert('columnMenuOpen event is Triggered');
}
let ganttInstance;
function columnMenuClick(){
alert('columnMenuClick event is Triggered');
}
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuOpen= { columnMenuOpen } columnMenuClick= { columnMenuClick }
allowFiltering={true} allowSorting={true}
splitterSettings={splitterSettings} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Sort, Filter, ColumnMenu]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Sort, Filter, ColumnMenu } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const splitterSettings: any = {
columnIndex : 5
};
function columnMenuOpen(){
alert('columnMenuOpen event is Triggered');
}
let ganttInstance:any;
function columnMenuClick(){
alert('columnMenuClick event is Triggered');
}
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuOpen= { columnMenuOpen } columnMenuClick= { columnMenuClick }
allowFiltering={true} allowSorting={true}
splitterSettings={splitterSettings} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Sort, Filter, ColumnMenu]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
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.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, ColumnMenu, ColumnDirective, ColumnsDirective } from '@syncfusion/ej2-react-gantt';
import { Inject, Sort } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
let ganttInstance;
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const columnMenuItems = [{text:'Clear Sorting', id:'ganttclearsorting'}];
const sortSettings = { columns:[{direction: "Ascending", field: "TaskName"}] };
function columnMenuClick(args){
if(args.item.id === 'ganttclearsorting'){
ganttInstance.clearSorting();
}
}
const splitterSettings = {
columnIndex : 5
};
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuItems={columnMenuItems} columnMenuClick={columnMenuClick} sortSettings={sortSettings} allowSorting={true}
splitterSettings={splitterSettings} height = '450px' ref={gantt =>ganttInstance = gantt}>
<ColumnsDirective>
<ColumnDirective field='TaskID' width='100' ></ColumnDirective>
<ColumnDirective field='TaskName' headerText='Task Name'></ColumnDirective>
<ColumnDirective field='StartDate'></ColumnDirective>
<ColumnDirective field='Duration'></ColumnDirective>
<ColumnDirective field='Progress'></ColumnDirective>
</ColumnsDirective>
<Inject services={[ColumnMenu, Sort]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, ColumnMenu, ColumnDirective, ColumnsDirective } from '@syncfusion/ej2-react-gantt';
import { ColumnMenuItemModel, Inject, Sort, SortSettingsModel } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
let ganttInstance: any;
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
const columnMenuItems: ColumnMenuItemModel[] = [{text:'Clear Sorting', id:'ganttclearsorting'}];
const sortSettings: SortSettingsModel = { columns:[{direction: "Ascending", field: "TaskName"}] };
function columnMenuClick(args: any){
if(args.item.id === 'ganttclearsorting'){
ganttInstance.clearSorting();
}
}
const splitterSettings: any = {
columnIndex : 5
};
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuItems={columnMenuItems} columnMenuClick={columnMenuClick} sortSettings={sortSettings} allowSorting={true}
splitterSettings={splitterSettings} height = '450px' ref={gantt =>ganttInstance = gantt}>
<ColumnsDirective>
<ColumnDirective field='TaskID' width='100' ></ColumnDirective>
<ColumnDirective field='TaskName' headerText='Task Name'></ColumnDirective>
<ColumnDirective field='StartDate'></ColumnDirective>
<ColumnDirective field='Duration'></ColumnDirective>
<ColumnDirective field='Progress'></ColumnDirective>
</ColumnsDirective>
<Inject services={[ColumnMenu, Sort]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
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.
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, ColumnMenu, ColumnDirective, ColumnsDirective, ColumnMenuOpenEventArgs } from '@syncfusion/ej2-react-gantt';
import { ColumnMenuItemModel, Inject, Sort, Filter } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
function columnMenuOpen (args) {
for (const item of args.items) {
if (item.text === 'Filter' && (args.column ).field === 'TaskName') {
(item ).hide = true;
} else {
(item ).hide = false;
}
}
}
const splitterSettings = {
columnIndex : 5
};
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuOpen={columnMenuOpen} allowFiltering={true} allowSorting={true}
splitterSettings={splitterSettings} height = '450px'>
<ColumnsDirective>
<ColumnDirective field='TaskID' width='100' ></ColumnDirective>
<ColumnDirective field='TaskName' headerText='Task Name'></ColumnDirective>
<ColumnDirective field='StartDate'></ColumnDirective>
<ColumnDirective field='Duration'></ColumnDirective>
<ColumnDirective field='Progress'></ColumnDirective>
</ColumnsDirective>
<Inject services={[ColumnMenu, Sort, Filter]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, ColumnMenu, ColumnDirective, ColumnsDirective, ColumnMenuOpenEventArgs } from '@syncfusion/ej2-react-gantt';
import { ColumnMenuItemModel, Inject, Sort, Filter } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
function columnMenuOpen (args: ColumnMenuOpenEventArgs) {
for (const item of args.items) {
if (item.text === 'Filter' && (args.column).field === 'TaskName') {
(item as ColumnMenuItemModel).hide = true;
} else {
(item as ColumnMenuItemModel).hide = false;
}
}
}
const splitterSettings: any = {
columnIndex : 5
};
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} showColumnMenu={true}
columnMenuOpen={columnMenuOpen} allowFiltering={true} allowSorting={true}
splitterSettings={splitterSettings} height = '450px'>
<ColumnsDirective>
<ColumnDirective field='TaskID' width='100' ></ColumnDirective>
<ColumnDirective field='TaskName' headerText='Task Name'></ColumnDirective>
<ColumnDirective field='StartDate'></ColumnDirective>
<ColumnDirective field='Duration'></ColumnDirective>
<ColumnDirective field='Progress'></ColumnDirective>
</ColumnsDirective>
<Inject services={[ColumnMenu, Sort, Filter]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>