If it is the first time I am inserting a link between two tasks, it will insert and post successfully. But if I delete a link, and try to recreate it. The ‘Insert Link’ doesn’t even reach my .NET RESTFUL method of ‘Insert Gantt Link’
Have you guys ever run into anything like this?
My OnBeforeLinkAdd custom event get’s hit. It just won’t go to my .NET code, unless it’s the first time inserting a link.
What happens when you delete a newly inserted link? Does it hit the backend method and the parameters are as they should be, i.e. do you get an actual link id instead of an auto-generated 13 digit number?
If it’s not, then maybe there is something wrong with the server response from the first ‘insert link’ request. Could you please show how the response body looks like?
And more generally, are there any errors in browser console?
When you add a link for the second time, is it added to the gantt client-side dataset or creation of new link is getting aborted for some reason? You can check it by serializing gantt in browser console
gantt.serialize() and then by checking out ‘links’ property of the result object - screencast.com/t/Ththzt3n5ac - newly added tasks have 13 digit numeric ids. If all works as it should, you’ll have no such links before adding the link for the second time, and exactly one such link after you add one.
So if i create a link the first time. It will post go through my .NET code and generate a true ID from my database. If I try to delete a newly created link it goes to the correct method in my controller and has the database ID that was just generated. There are no errors in my console, but I am going to post some of my code and what gets printed from the console.
Controller Code:
[HttpPost]
[Route("gantt/link")] // must be <BaseURL>/link to work with gantt
public ActionResult InsertGanttLink(TaskLinkDetailApiModel m)
{
try
{
m.Id = 0;
var saved = _ganttBl.Save(m);
var response = new { action = "inserted", sid = $"{int.MaxValue}", tid = $"{saved.Id}" };
//var response = new { action = "inserted", sid = $"{m.Id}", tid = $"{saved.Id}" };
return Json(response);
}
catch (Exception ex)
{
_log.Error(ex);
var response = new { action = "error", sid = $"{m.Id}", tid = $"{m.Id}", details = ex.Message };
return Json(response);
}
}
Javascript Code:
[code]
gantt.attachEvent(“onBeforeLinkAdd”,
function (id, link) {
console.log(“On Before Link Add Function :” + id);
link.id = maxValueInt;
});
gantt.attachEvent("onBeforeLinkDelete", function (id, item) {
//any custom logic here
console.log("On Before Link Delete Function :" + id);
return true;
});[/code]
The gantt.serialize appears to be returning the correct data. Unless I am missing something.
The link between 16111 - 17437 ID = 14801
The link between 16113 - 16114 ID = 13704
Please let me know if you need more info. I might need to open an official support ticket, because this issue is popping up more as our projects grow. I am a pro member, but I know you guys are very responsive on the forums, so i was hoping you could look into it a little more.
Hi,
sorry for a delay.
I’m still not sure what could have caused your issue, but if it’s still actual you can try one thing:
In your JS code you change an id of a newly inserted link: gantt.attachEvent("onBeforeLinkAdd",
function (id, link) {
console.log("On Before Link Add Function :" + id);
link.id = maxValueInt;
});
And then you return int max value as ‘sid’ from controller code :
var response = new { action = "inserted", sid = $"{int.MaxValue}", tid = $"{saved.Id}" };
That’s a bit different from a regular flow since usually you don’t change ids from code, and maybe that’s the reason.
Please try removing onBeforeLinkAdd handler from JS code, and omit ‘sid’ property from controller response (it should work if you skip it)
var response = new { action = "inserted", tid = $"{saved.Id}" };
I was very optimistic about this change, but it did not work. Is there anything else I can provide you to debug this problem? I tried debugging it, and it never reaches my .NET server code. So changing the response in the controller didn’t affect anything.
If you look at the image I uploaded - I cannot add a link between Schedule Port-a-Pot and Construction. I can’t add any type of link: (Start to Start, Start to End)
I added the two children tasks ‘Notify Concrete 1, and Notify Concrete 2’ under the Parent Notify Concrete task. As I try to re link all the tasks, by deleting the old links then redrawing them I eventually hit a snag. (At Schedule-Port-a-Pot and Construction)
**Edit - I could provide you with my entire custom Gantt JavaScript file if that would be beneficial. I am at such a roadblock.
Somehow this seems to have gotten resolved when I updated to Gantt 4.1.9. Previously we were using 4.0. I don’t know what happened between the updates, but I am able to add links again. (Thank God!)
Thanks for the help.
Ben
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan