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);


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.



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: ; ;
So your onAfterTaskDelete event should look like:

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

Please check the following example: