Search results

Open Add Edit Dialog Dynamically in JavaScript (ES5) Gantt control

08 May 2023 / 1 minute 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.

Source
Preview
index.js
index.html
Copied to clipboard
ej.gantt.Gantt.Inject(ej.gantt.Edit);

var ganttChart = new ej.gantt.Gantt({
        dataSource: GanttData,
		height:'450px',
		taskFields: {
            id: 'TaskID',
            name: 'TaskName',
            startDate: 'StartDate',
			duration: 'Duration',
            progress: 'Progress',
			child: 'subtasks'
        },
		editSettings: {
		   allowEditing:true,
           allowAdding: true
         }
});
ganttChart.appendTo('#Gantt');

var editBtn= new ej.buttons.Button();
editBtn.appendTo('#editDialog');

var addBtn= new ej.buttons.Button();
addBtn.appendTo('#addDialog');

document.getElementById('editDialog').addEventListener('click', () => {
    ganttChart.editModule.dialogModule.openEditDialog();
});

document.getElementById('addDialog').addEventListener('click', () => {
    ganttChart.editModule.dialogModule.openAddDialog();
});
Copied to clipboard
<!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/21.2.3/material.css" rel="stylesheet" type="text/css">
    
    
<script src="https://cdn.syncfusion.com/ej2/21.2.3/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>

<body>
    <button id="editDialog">Open EditDialog</button> <button id="addDialog">Open AddDialog</button>
    
    <div id="container">
        <div id="Gantt"></div>        
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

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