Problem when deleting a task with subtasks (and REST)

I’m doing this with REST… the function deleteTask , when I execute in a parent task, do its job of delete all descendants. However, the way hes doing this is sending a request per task to delete. This is not good for a business tier on server… I think the logic to delete descendants would be a server problem.

One big problem came up with this approach… As requests are being created per task on subtree, and requests are asynchronous, so I have problem when a certain task is being requested to delete before it child. I even think that the order of the requests are inverted, when I look to the order the where sending in network… the parents are going first.

I’d like to have only the request for the task I clicked to delete. Can I achieve this?

Hello.

Unfortunately, currently there is no correct way to achieve it.
But you could try to achieve it with “_deleteTask” function. Currently this one gets two arguments “id” and “silent”. If second one is set to true it won’t call delete events, initiate dataProcessor to send requests and redraw gantt data.
So you could try to call task removing in silent mode. Then you could call “onAfterTaskDelete” event because dataProcessor listens for this one to send delete request. And then, you could call “refreshData” to redraw gantt data according to removed tasks.
For example, something like following:

var id = 3,
    task = gantt.getTask(id);

gantt._deleteTask(id, true);
gantt.callEvent("onAfterTaskDelete",[id, task]);
gantt.refreshData();

Hello Sten,

Thank you so much, it worked as you proposed.

I have overwriten the function “deleteTask” as the code bellow:

gantt.deleteTask = function (id){
    task = gantt.getTask(id);
    
    gantt.callEvent("onBeforeTaskDelete",[id, task]);
    gantt._deleteTask(id, true);
    gantt.callEvent("onAfterTaskDelete",[id, task]);
    
    gantt.refreshData();
}