$('#ganttContainer').ejGantt({
dateFormat: "dd/MM/yyyy",
isResponsive: true,
dataSource: data, //Provides data source for Gantt
taskIdMapping: "taskID", //Provide name of the property which contains task id in the data source
taskNameMapping: "taskName", //Provide name of the property which contains task name in the data source
startDateMapping: "startDate", //Provide name of the property which contains start date of the task in the data source
durationMapping: "duration", //Provide name of the property which contains duration of the task in the data source
progressMapping: "progress", //Provide name of the property which contains progress of the task in the data source
notesMapping: "notesContent",
predecessorMapping:"predecessor" ,// Predecessor editing
childMapping: "subtasks", //Provide name of the property which contains subtask of the task in the data source
resourceInfoMapping: "resourceId", //Field name which contains resource details for the task
resourceNameMapping: "resourceName",//resource Name mapping
resourceIdMapping: "resourceId",//resource Id Mapping
resources: projectResources,//resource collection dataSource
create: function () {
this.showCriticalPath(true);
},
load: load,
scheduleHeaderSettings:{
weekendBackground : "#F2F2F2",
weekHeaderFormat : "MMM dd , yyyy"
},
toolbarSettings: {
showToolbar: true,
toolbarItems: [
ej.Gantt.ToolbarItems.Search,
ej.Gantt.ToolbarItems.ExcelExport,
ej.Gantt.ToolbarItems.PDFExport,
],
},
toolbarClick: toolbarClick,
allowGanttChartEditing:true, //enable the taskbar editing
editSettings: {
// allowAdding: true,
allowEditing: true,
allowDeleting: true,
allowTaskbarEditing: true,
// showDeleteConfirmDialog: true,
mode: 'Dialog'
},
allowSelection: true,
columns: [
{ field: 'taskID', headerText: 'ID', textAlign: 'Left', width: '300', mappingName: "taskID"},
{ field: 'name', headerText: 'Tarefa', width: '200', minWidth: '150', mappingName: "taskName", maxWidth: '250', editType: "stringedit" },
{ field: 'inicio', headerText: 'Data Inicial',mappingName: "startDate", width: '150', editType: "datePicker" },
{ field: 'fim', headerText: 'Data Final',mappingName: "endDate", width: '150', editType: "datePicker" },
{ field: 'duracao', headerText: 'Duração', width: '100', minWidth: '50',mappingName: "duration", maxWidth: '200'},
{ field: 'progress', headerText: 'Progresso',mappingName: "progress", width: '150' },
{ field: 'notesContent', headerText: 'Obs', width: '200', mappingName: "notesContent" },
{ field: 'predecessor', headerText: 'Predecessores', width: '200', mappingName: "predecessor" },
{ field: 'resourceId', headerText: 'Recursos', width: '200', mappingName: "resourceId" },
],
actionComplete: function (args) {
console.log(args)
//console.log(args.data.length)
if (args.requestType === "recordUpdate") {
var encoded = JSON.stringify(args.data.item),
data = encoded;
console.log('encoded ' +data)
for (var i = 0; i < args.updatedRecords.length; i++) {
var id = args.updatedRecords[i].item.taskID;
var start = args.updatedRecords[i].item.startDate;
var end = args.updatedRecords[i].item.endDate;
// var predecessors = args.data.item[i].Predecessor;
console.log('Updates na taskID '+ id)
//save changes to the database
// sendData(id, start, end, predecessors);
}
}
if(args.requestType === "drawConnectorLine"){
console.log('predecessor ' +args.toItem.taskId)
console.log('fromItem ' + args.fromItem.taskId )
}
if(args.requestType == "openEditDialog") {
console.log('oi')
var tasknameField = (document.getElementById("EditingTaskName")).ej2_instances[0];
tasknameField.enabled = false; //.... Disabled TaskName field from editing
}
},
projectStartDate: new Date('01/02/2020'),
projectEndDate: new Date('15/06/2020'),
});
});