- Built-in toolbar items
- Custom toolbar items
- Built-in and custom items in toolbar
- Enable/disable toolbar items
- Add input elements to toolbar
Contact Support
Tool bar in EJ2 TypeScript Gantt control
2 May 202318 minutes to read
The Gantt control provides the toolbar support to handle Gantt actions. The toolbar
property accepts the collection of built-in toolbar items and ItemModel
objects for custom toolbar items.
Built-in toolbar items
Built-in toolbar items execute standard actions of the Gantt control, and these items can be added to toolbar by defining the toolbar
as a collection of built-in items. It renders the button with icon and text.
The following table shows built-in toolbar items and its actions.
Built-in Toolbar Items | Actions |
---|---|
Add | Adds a new record. |
Cancel | Cancels the edit state. |
CollapseAll | Collapses all the rows. |
Delete | Deletes the selected record. |
Edit | Edits the selected record. |
Indent | Indent the selected record to one level. |
Outdent | Outdent the selected record to one level. |
ExpandAll | Expands all the rows. |
NextTimeSpan | Navigate the Gantt timeline to next time span. |
PrevTimeSpan | Navigate the Gantt timeline to previous time span. |
Search | Searches the records by the given key. |
Update | Updates the edited record. |
import { Gantt, Toolbar, Selection, Edit, Filter } from '@syncfusion/ej2-gantt';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Toolbar, Selection, Edit, Filter);
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['Add', 'Cancel', 'CollapseAll', 'Delete', 'Edit', 'ExpandAll', 'NextTimeSpan', 'PrevTimeSpan', 'Search', 'Update', 'Indent', 'Outdent'],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true
}
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.2.3/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>
- The
toolbar
has options to define both built-in and custom toolbar items.
Custom toolbar items
Custom toolbar items can be added to the toolbar by defining the toolbar
property as a collection of ItemModels
.
Actions for this customized toolbar items are defined in the toolbarClick
event.
By default, the custom toolbar items are at left position. You can change the position by using the align
property. In the following sample, the Quick Filter
toolbar item is positioned at right.
import { Gantt, Toolbar, Filter } from '@syncfusion/ej2-gantt';
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Toolbar, Filter);
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbarClick: (args: ClickEventArgs) => {
if (args.item.id === 'toolbarfilter') {
gantt.filterByColumn('TaskName', 'startswith', 'Identify');
}
},
toolbar: [{ text: 'Quick Filter', tooltipText: 'Quick Filter', id: 'toolbarfilter', align: 'Right', prefixIcon: 'e-quickfilter' }],
allowFiltering: true
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.2.3/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>
- The
toolbar
has options to define both built-in and custom toolbar items.- If a toolbar item does not match the built-in items, it will be treated as a custom toolbar item.
Built-in and custom items in toolbar
The Gantt control has an option to use both built-in and custom toolbar items at the same time.
In the following example, the ExpandAll
and CollapseAll
are built-in toolbar items and Test
is the custom toolbar item.
import { Gantt, Toolbar, Filter } from '@syncfusion/ej2-gantt';
import { EmitType } from '@syncfusion/ej2-base';
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Toolbar, Filter);
let clickHandler: EmitType<ClickEventArgs> = (args: ClickEventArgs) => {
if (args.item.text === 'Test') {
alert("Custom toolbar click...");
}
};
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbarClick: clickHandler,
toolbar: ['ExpandAll', 'CollapseAll', { text: 'Test', tooltipText: 'Test', id: 'Test' }]
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.2.3/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>
Enable/disable toolbar items
You can enable or disable the toolbar items by using the enableItems
method.
import { Gantt, Toolbar, Filter } from '@syncfusion/ej2-gantt';
import { Button } from '@syncfusion/ej2-buttons';
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Toolbar, Filter);
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['QuickFilter', 'ClearFilter'],
toolbarClick: (args: ClickEventArgs) => {
if (args.item.text === 'QuickFilter') {
gantt.filterByColumn('TaskName', 'startswith', 'Identify');
}
if (args.item.text === 'ClearFilter') {
gantt.clearFiltering();
}
},
allowFiltering: true
});
gantt.appendTo('#Gantt');
let enable: Button = new Button({}, '#enable');
let disable: Button = new Button({}, '#disable');
enable.element.onclick = () => {
gantt.toolbarModule.enableItems([gantt.element.id + '_QuickFilter', gantt.element.id + '_ClearFilter'], true);// enable toolbar items.
};
disable.element.onclick = () => {
gantt.toolbarModule.enableItems([gantt.element.id + '_QuickFilter', gantt.element.id + '_ClearFilter'], false);// disable toolbar items.
};
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.2.3/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<button id="enable" class="e-flat">Enable</button>
<button id="disable" class="e-flat">Disable</button>
<div id='Gantt'></div>
</div>
</body>
</html>
Add input elements to toolbar
In the Gantt toolbar, you can add EJ2 editor elements like numeric text box, drop-down list, and date picker controls. The following code snippets demonstrates how to add EJ2 editors to the Gantt toolbar.
import { Gantt, Toolbar } from '@syncfusion/ej2-gantt';
import { NumericTextBox} from '@syncfusion/ej2-inputs';
import { GanttData } from 'datasource.ts';
Gantt.Inject(Toolbar);
let gantt: Gantt = new Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: [{ type: 'Input', template: new NumericTextBox({ format: 'c2', value:1, width:150 }) }]
});
gantt.appendTo('#Gantt');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Gantt Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.2.3/material.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='Gantt'></div>
</div>
</body>
</html>