Delete parent task using gantt.deleteTask

Hi support,
I am using gantt.deleteTask method to delete tasks in Gantt. In my senario I want to update custom property called sortOrder after delete parent task with children.

for this purpose I used
gantt.attachEvent(“onAfterTaskDelete”, function(id:string,item:GanttTaskInfo){

//update the order of tasks
gantt.batchUpdate(function () {
gantt.eachTask(function (item: any) {

    item.sort_order = item.$index + 1;
   gantt.updateTask(item.id, item);

})
},null)

but at the time is event in calling , the deleted task also taking to account. then remaining tasks sortorder is not correct.
Can you please let me know how i update remaining tasks sort order.

Thanks.
Rasagb

Hello,
After you deleted a project or a task, you need to recalculate the positions of the tasks by redrawing Gantt. You can do it by refreshData or render methods:
https://docs.dhtmlx.com/gantt/api__gantt_refreshdata.html ;
https://docs.dhtmlx.com/gantt/api__gantt_render.html ;
So your onAfterTaskDelete event should look like:

gantt.attachEvent('onAfterTaskDelete', function (id, item) {
    gantt.refreshData();
    gantt.batchUpdate(function () {
        gantt.eachTask(function (item) {
            item.sort_order = item.$index + 1;
            gantt.updateTask(item.id);
        })
    })
})

Please check the following example:
https://snippet.dhtmlx.com/2gtiz0ym