Initial Order with dragdrop on createTask not included in api

Hi,

I created dragdrop functionally in Gantt. (I drop on the gantt itself, not using + in sidebar) All is well. Task is created on the right spot. But after reloading the task drops to the bottom. This seems logical because in php the store methode creates the sort order by adding 1 to the last sort order.

How can I append/send the task.index with the createTask methode in JS so I can calculate the order just as is done with the updateTask api call, as the index is not provided on the call to the backend.

With the updateTask “target” is provided in the request. But not so on createTask.

Regards,

Robin

        function onDragEnd(startPoint,endPoint,startDate,endDate,tasksBetweenDates,tasksInRow){
            if (tasksInRow.length === 1) {
                var parent = tasksInRow[0];
                // var index = tasksInRow[0].$index+1;
                var index = gantt.getTaskIndex(parent.id);
                console.log(parent);
                gantt.createTask({
                    text:"New task",
                    start_date: gantt.roundDate(startDate),
                    end_date: gantt.roundDate(endDate),
                }, parent.parent, index);
            } else if (tasksInRow.length === 0) {
                gantt.createTask({
                    text:"New task",
                    start_date: gantt.roundDate(startDate),
                    end_date: gantt.roundDate(endDate),
                } );
            }
        }

Hello Robin,
The onTaskCreated event fires when you click on the “+” button in Gantt, but before you click on the Save button to apply the changes. At that time, the task object doesn’t have most of the temporary and system parameters:
https://docs.dhtmlx.com/gantt/desktop__task_properties.html

You can try using the $local_index property in the onBeforeTaskAdd or onAfterTaskAdd events:
https://docs.dhtmlx.com/gantt/api__gantt_onaftertaskadd_event.html
https://docs.dhtmlx.com/gantt/api__gantt_onbeforetaskadd_event.html

Here is the snippet:
http://snippet.dhtmlx.com/5/0fb18dda2