Gantt how to delete links from database

Hi
I want to delete Task with it’s related links.

		gantt.attachEvent("onBeforeTaskDelete", function (id, item) {
		//any custom logic here

		var sourceLinks = item.$source;
		var targetLinks = item.$target;
		for (let i = 0; i < sourceLinks.length; i++) {
			gantt.deleteLink(sourceLinks[i]);
		}
		for (let j = 0; j < targetLinks.length; j++) {
			gantt.deleteLink(targetLinks[j]);
		}

		return true;
	});

in this code deltes the first link and does not wait for response. Does not delete second related link and again deletes third link and so on. Is there any way to await the deleteion until response?

Thanks in advance.

Hello Komek,
Usually, when you delete a task, Gantt deletes all its links. I tried to reproduce it, and it works correctly.
Could you clarify if you want to delete links before deleting a task and why do you need that?

Hello Ramil.
Tanks for your reply. I want to delete task. and when I delete task I want to delete all related links to the task.
I used below codes for deleting related links to the task.

	gantt.attachEvent("onBeforeTaskDelete", function (id, item) {
		//any custom logic here

		var sourceLinks = item.$source;
		var targetLinks = item.$target;
		for (let i = 0; i < sourceLinks.length; i++) {
			gantt.deleteLink(sourceLinks[i]);
		}
		for (let j = 0; j < targetLinks.length; j++) {
			gantt.deleteLink(targetLinks[j]);
		}

		return true;
	});

    gantt.attachEvent('onAfterLinkDelete', (id) => {
		this.linkService.remove(id);
	});

and in service

remove(id: number): Promise<void> {
	return this.post('api/1.0/Gant/GorevSil', id)
	.toPromise();
}

link

in this situation when I delete task “New task 5”, I want to delete all links from db.
the above code deletes the links from “New task 1” to “New task 5” and from “New task 3” to “New task 5”,
does not delete link between “New task 2” to “New task 5”.
So is there any way await the procedure until first delete operation completed or anything like this?

Thanks

Hello Komek,
Thank you for the clarification.
Usually, it should work out of the box if you use the Data Processor:
https://docs.dhtmlx.com/gantt/desktop__server_side.html
https://docs.dhtmlx.com/dataprocessor__index.html
Here is the video that demonstrates that:
https://files.dhtmlx.com/30d/9183c5c87012683d85938e706b565d54/vokoscreen-2019-03-27_15-22-38.avi

Could you check how it works without that event handler?

Hello Ramil.
I get the below error in angular 7.
Can you help?
Thanks.

Hello Komek,
Unfortunately, I cannot reproduce that issue. Here is the demo:
https://files.dhtmlx.com/30d/35b3f1349f85b39eb958154b370e08e4/angular7+gantt.zip
If that doesn’t help you, please, send me your project as it is hard to suggest what might be wrong without being able to see your code.

Hello Ramil.
Thanks for your help.
I copied dhtmlxgantt.js and dhtmlxgantt.js.map files from demo you give link above, to my project’s files.
I worked without any problem. Thanks again.