Unexpected ID when adding task and using server-side data

Hi,

I’m seeing an unexpected behaviour regarding the returned ID when I’m using server-side data and add tasks. I believe it might be due to a bug.

If I am to add a task, I use the gantt.addTask method as described here:
http://docs.dhtmlx.com/gantt/api__gantt_addtask.html

The actual call:

var taskId = gantt.addTask({ id:10, text:"Task #5", start_date:"02-09-2013", duration:28 }, "project_2");

Example 1 - using local data everything works as expected

Now, if I go to your demo page with a very basic gantt…
http://docs.dhtmlx.com/gantt/samples/01_initialization/01_basic_init.html
…and open the javascript console, I can add a task and get its’ ID back:

gantt.addTask({ text: "Test", start_date: "2014-04-04", duration: 2, progress: 0, type: "task" });

returns 1405940833173

Now I can use that ID to get the task I just added:

gantt.getTask(1405940833173);

returns the object

Example 2 - using server-side data the returned ID is wrong

However, if I do this on your demo that’s using server-side data…
http://docs.dhtmlx.com/gantt/samples/01_initialization/04_connector_json.html
…and perform the exact same operation I get this instead:

gantt.addTask({ text: "Test", start_date: "2014-04-04", duration: 2, progress: 0, type: "task" });

returns 1405940929703

Now I once again try to get the task by using the returned ID:

gantt.getTask(1405940929703);

returns undefined

And if I look through all tasks, I do find it, with a completely different ID:

gantt.eachTask(function(task){console.log(task.id + " " + task.text);})

returns 145 Test

I would expect the ID returned from an addTask method to be the actual ID, regardless of my data being local or server-side based. Could this be a bug?

Thanks,
Fred S

The next occurs in the second case

  • addTask called, event added to the gantt, correct ID returned
  • gantt sent data to the server side, that is asyn process, so it takes some time
  • while inserting in DB, new ID generated and returned to the client side
  • id of record in the gantt updated with actual value

So after some time, the ID that you have received becomes invalid.
There is a onTaskIdChange event, that is related to the above case
docs.dhtmlx.com/gantt/api__gantt … event.html

Hmm… Understood, thanks. That makes sense, but it also makes things a little bit more complicated if I’m relying on using that ID for other things just after creating the task.

This might be a stupid question, but I have to ask: Would it be possible for you to add an optional property to addTask so that I can control that the call to the server shouldn’t be asyn? I wouldn’t really mind having to wait half a second and as an effect being able to use the updated ID directly.

Locate the next line in code of dhtmlxGantt

var a2=new dtmlXMLLoaderObject(this.afterUpdate,this,true);

and replace it like next

var a2=new dtmlXMLLoaderObject(this.afterUpdate,this,false);

We will consider adding a public property for sync data saving mode.