Bug in Gantt with server-side data when adding a project?

Hi,

I’m trying out Gantt for a project using server-side data and found myself having strange problems adding projects (but not tasks or milestones). Hunting for the problem led me to what I’m about to show below. While not entirely certain, I believe there might be a bug in gantt. To be sure to exclude my own potential buggy code I’ll show this using one of your own demos and using only the javascript console.

To see this, please follow along using these steps:

Go to this gantt demo page: (it’s relevant as it also uses server-side data)
http://docs.dhtmlx.com/gantt/samples/01_initialization/04_connector_json.html
(If it’s cluttered, feel free to remove all current tasks, they are not needed to show the problem)

Open the javascript console and add a task of type “task”:

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

Lookup id of just added task

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

Outputs (for instance)

132 Test

Take a look at the task (for verification purposes only)

gantt.getTask(132);

Looking at the object, it contains this

$index 1 $level 1 $no_end false $no_start false $open false $rendered_parent 1 $rendered_type "task" $source [] $target [] duration 2 end_date Mon Jul 21 2014 00:00:00 GMT+0200 (CEST) {} id "132" parent 1 progress 0 start_date Sat Jul 19 2014 00:00:00 GMT+0200 (CEST) {} text "Test" type "task"

Up to this point everything works as expected.

Now change the type to “project”

gantt.getTask(132).type = "project"; gantt.updateTask(132);

Take another look at the task (now being a “project”)

gantt.getTask(132);

Produces

$index 1 $level 1 $no_end true $no_start true $open false $rendered_parent 1 $rendered_type "project" $source [] $target [] duration "" end_date "" id "132" parent 1 progress 0 start_date "" text "Test" type "project"

Meaning that the values in these fields were emptied…

duration 2 end_date Mon Jul 21 2014 00:00:00 GMT+0200 (CEST) {} start_date Sat Jul 19 2014 00:00:00 GMT+0200 (CEST) {}

…and these values in these fields were changed (probably as result of emptied fields above)

$no_end true $no_start true

At this point everything still looks fine in the gantt, but as soon as I trigger a redraw (using gantt.render() for instance), the Test task gets a single pixel width to the far left of the visual bar-area. I also get three “invalid day index” errors.

All help and comments appreciated,
Fred S

PS. It’s probably worth noting that this problem does not exist if one instead tries it out on this demo: http://docs.dhtmlx.com/gantt/samples/01_initialization/01_basic_init.html. Probably because it’s not server-side data?

Thanks for detailed description.

There are two parts in above behavior:
a) empty start and end date - this is actually expected. The “project” task defined by start and end dates of child tasks. In your case it is empty ( doesn’t have child tasks ) so project collapsed to a line.

b) “invalid day index” errors and collapsing to the single line - errors must not appear for sure, and project task without sub-tasks must occur at least a single cell - both will be fixed in the next update

Thank you very much for your fast response.

I’m not entirely sure, but I think that maybe it would be better for a project without children to actually keep - and use - its’ start and end date. That way I, being in control of the actual data, could massage it to whatever suits my needs.

Do you have an estimate for when the next version will be released?

Thanks,
Fred S

The only difference of “project” from the “task” is that calculates its position and size automatically ( also, it has a bit different styling - but it can be done with normal tasks as well ). So if you need a project with fixed dates - why not use common “task” type for it ?

Yes, I realize those are the only differences. And I’m not in need of a project with fixed dates.

I’m merely suggesting that in the special (and probably unusual) case where a project have no children, it might make sense to render the project using the start_date and duration connected to the object. At least, in that case, I will have a way of overriding it myself and coding it to just being one day if it has no children.

Did this clarify my thoughts?

Best,
Fred S

Yes, now I see.

We will update the above behavior in the next build, most probably the project task without child tasks will always fall back to 1 unit length ( 1 day in case of day based scale ).

Solution with date preserving can be added as well, but it will introduce a difference in “project” bar behavior, which is auto-sized in one case, but can be set to custom length in other case. I’m not sure that it will be more helpful than confusing.