Open add edit dialog in EJ2 TypeScript Gantt control

2 May 20233 minutes to read

Gantt add and edit dialogs can be opened dynamically by using openAddDialog and openEditDialog methods. The following code example shows how to open add and dialog on separate button click actions.

import { Gantt, Edit, Selection } from '@syncfusion/ej2-gantt';
import { Button } from '@syncfusion/ej2-buttons';
import { GanttData } from 'datasource.ts';
import { getValue } from  '@syncfusion/ej2-base';

Gantt.Inject(Edit, Selection);

let gantt: Gantt = new Gantt({
    dataSource: GanttData,
    height: '450px',
    taskFields: {
        id: 'TaskID',
        name: 'TaskName',
        startDate: 'StartDate',
        duration: 'Duration',
        progress: 'Progress',
        child: 'subtasks'
    editSettings: {
        allowAdding: true,
        allowEditing: true,
        allowTaskbarEditing: true


let editBtn: Button = new Button();

let addBtn: Button = new Button();

document.getElementById('editDialog').addEventListener('click', () => {
    gantt.editModule.dialogModule.openEditDialog(getValue('TaskID', gantt.selectionModule.getSelectedRecords()[0]));

document.getElementById('addDialog').addEventListener('click', () => {
<!DOCTYPE html>
<html lang="en">

    <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="" rel="stylesheet" type="text/css"/>
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>

    <button id="editDialog">Open EditDialog</button> <button id="addDialog">Open AddDialog</button>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='Gantt'></div>        


NOTE: We should select any one of the row in Gantt to open the edit dialog.