Error when adding new record

Hi,

I'm implementing a context menu with addtask option. The idea is to add a new task that starts when the right-clicked task ends.:

onganttcontextMenuOpen(args) {
args.contextMenuItems.push({
headerText: "Add Preparation Task",
menuId: "preTask",
iconClass: "e-prepTaskIcon",
eventHandler: function() {
//event handler for custom menu items
var rowPosition = args.model.dataSource[args.model.dataSource.length - 1].subtasks[args.model.dataSource[args.model.dataSource.length - 1].subtasks.length - 1].taskID +1;
var data = {taskID: rowPosition, taskName:"Preparation Task", startDate: args.item.endDate, duration: 1, itemType: "PR"};
this.addRecord(data, rowPosition);
}
});
}

With this code it throws this error:

errors.js:55 ERROR TypeError: Cannot read property 'startDate' of undefined
    at Object._updateScheduleDatesOnEditing (ej.gantt.min.js:10)
    at Object._ganttActionCompleteTrigger (ej.gantt.min.js:10)
    at Object.actionComplete (ej.gantt.min.js:10)
    at Object.addRecord (ej.gantt.min.js:10)
    at Object.eventHandler (scheduler.component.ts:768)
    at Object._triggerMenuEventHandler (ej.gantt.min.js:10)
    at Object._contextMenuClickHandler (ej.gantt.min.js:10)
    at HTMLDivElement.eval (ej.gantt.min.js:10)
    at HTMLDivElement.dispatch (VM701246 jquery.min.js:2)
    at HTMLDivElement.y.handle (VM701246 jquery.min.js:2)

Any idea?

Thanks.



1 Reply

PE Punniyamoorthi Elangovan Syncfusion Team June 25, 2018 12:40 PM UTC

Hi Oscar, 
Thank you for contacting Syncfusion support 
We have analyzed your reported issue and code snippet. In Gantt when add the new record by using addRecord public method then we have to pass the data and rowPosition as an argument to that method. The rowPosition defines in which position the row wants to add in Gantt. Please find more details about this method is here. 
The issue is persisting in your sample because in your code snippet the rowPosition has the value in Numeric. We suggest you to please refer the below code snippet to overcome the reported issue. 
[HTML] 
<ej-gantt id="ganttcontrol" [enableContextMenu]="true" 
    (contextMenuOpen)="onganttcontextMenuOpen($event)"> 
</ej-gantt> 
 
[TS] 
onganttcontextMenuOpen(args) { 
        args.contextMenuItems.push({ 
            headerText: "Add Preparation Task", 
            menuId: "preTask", 
            eventHandler: function (args) { 
                var data = { TaskName: "Preparation Task", StartDate: args.data.item.EndDate, duration: 1, Progress: "80" }; 
                this.addRecord(data, ej.Gantt.RowPosition.BelowSelectedRow); 
            } 
        }); 
    } 
 
We have prepared the sample for your reference please find the sample link below 
 
Please let us know if you require further assistance on this. 
Regards, 
Punniyamoorthi 



Loader.
Up arrow icon