I’m trying to get the index of a task created on onAfterTaskAdd event, but I get undefined or -1 using “$index” property or using gantt.getGlobalTaskIndex.
I’m not sure I understand you correctly, but I’ve tried to reproduce your issue in this snippet. Please open it and click on the + and Add new task buttons. Look at the messages in the top right with hte indexes of created tasks: http://snippet.dhtmlx.com/e99845e72
As you can see, when “$index” is called an “undefined” is obtained. This time, gantt.getGlobalTaskIndex throws right, but I think that it does because it wins on race conditions. My code on the “onAfterTaskAdd” event is actually more longer than this example, so in the console of my code it actually keeps evaluating while the event execution doesn’t finished yet; this is just an assumption, so I’m not plenty sure about this.
Hello,
The $index parameter is undefined because although the task is added, it is not displayed in the chart. The gantt.getGlobalTaskIndex(id) command calculates the index.
You can see how it works in the following snippet: http://snippet.dhtmlx.com/1500540b3 gantt.getTaskRowNode returns the div element of the task row in the grid. That element appears only after the data is rendered on the page.
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan