When using + to add a numeric id gets inserted

If I use the + to insert a task, the ID that gets generated is a numeric and is not enclosed in double quotes so when I pull the JSON off the gantt and stringify it, I get that numeric only value and that screws up the parser I am sending that to… How best can I update the ID there? I am already creating a shadow ID called Order to be used for something else and I do that in the beforerender. If I try to modify ID in the eachTask it seems to generate an error.

So how best can I override this there? Here is current gen of order

gantt.attachEvent(“onBeforeGanttRender”, function(){

var ii = 1;
gantt.eachTask(function(task){
 var myorder = ii++ ;
 task.order = myorder.toString();   
});

});


1 Like

Hi,

To solve the issue please add this code before gantt configurations:

var uid = gantt.uid; gantt.uid = function(){ return uid() + ""; };
Here is an example how it works.
Now new task has string id, please check the screenshot.

1 Like

I had a similar issue, and you answer solves the problem, thanks!
However, isn’t it a bug? I think the id should be string by default as even the examples here
https://docs.dhtmlx.com/gantt/desktop__task_object_operations.html
use string ids.

Hello Subri,
Gantt doesn’t add the strict check for IDs as in some places you can use String types, in other places, you can use Number types.
The ID can have the Number or String type.

In the examples you mentioned, there are only String types are possible.
Here is an article about data loading, there are Number types for task IDs:
https://docs.dhtmlx.com/gantt/desktop__loading.html