Question regarding per-task worktime settings

Hi,

I need to specify worktime per task. Meaning that if I have a gantt with two tasks in it, I need to specify that task 1 don’t work on Saturdays and Sundays. But, on the other hand, task 2 work all days except Sundays. (In theory I could need more variations, but these two use-cases seem to be by far the most common for me.)

I don’t think this is possible to do with current version of dhtmlxGantt, is that correct?

I also have a vague memory of this functionality being introduced in the next version (but I can’t seem to find where I read that). Is this correct?

If this is something that will be added soon, would it be possible to get an indication for when that version would be available?

All help and info is greatly appreciated,
Fred S

Hello,
yes, it is not supported in the current version of the gantt. Unfortunately, the upcoming version (dhtmlxGantt v.3.0) also does not have such functionality.

The per-task work time is added in the to-do list for future updates, but currently it’s not decided when it will be implemented. It may be one of the minor releases which will be launched during the year, or in the next major update next Summer

Understood, thanks for the reply. I have a couple of follow-up questions.

1. Can I code around this limitation?
If I would like to do this with the current version of the gantt, could I simply perform the logic in my own function, myCustomCalculateEndDate?

I would imagine I’d have to use it after these events (but before it’s synced to server) to ensure it has a correct end date:

  • User changes task duration (by entering a number)
  • User resizes task by dragging start/end handles
  • User moves task

Is this too naïve? Would I miss something important somewhere else?

2. How can I show this visually?
Also, if the task goes from Wednesday to Tuesday, is there a reasonably simple way for me to just color the Sunday-part of the task-bar in a different color to show that it’s a day off even though the task stretches over that day? (I’m aware of setting classes for the tasks, but I’m not sure how I would accomplish just making a part of it different.)

Thanks,
Fred S

Hi,
right now I can’t think of a more or less clean way to implement it.

There are several public methods that are responsible for working time calculations, see methods between these lines:
github.com/DHTMLX/gantt/blob/v2 … t.js#L5116
github.com/DHTMLX/gantt/blob/v2 … t.js#L5137

The component uses this methods to calculate all times. The helper that performs the calculation is defined here
github.com/DHTMLX/gantt/blob/v2 … t.js#L4654

The complicated part is that all this methods not work on the task level. From inside the method there is no way to know for which task it was called.
You can modify the methods so they would take a related task in parameters:

gantt.isWorkTime(task.start_date, unit, task)

where ‘unit’ is a type of time unit to be checked - ‘day’, ‘hour’, current duration unit by default;

and redefine the helper that does the calculation, in order to add a support of a task-related work times. If you do this, the task durations will be calculated regarding the individual settings.

However, in order to make it work, you’ll have to modify each call of calculateEndDate, isWorkTime, calculateDuration, etc in source codes in order to pass the related task object to the helper (pass task object as parameter of these methods).
This will create a lot of troubles with updating to the new versions of the component

Hi,

Thanks for your detailed answer, I think I understand what you are saying. And I’m not really interested in diving into your code and hacking it. As you say, that will surely bring lots of problems later on.

Instead I would like to try another idea on you to see if this might be a way forward:

Would it be possible to expose calculateEndDate as an event, so I could do this:

[code]gantt.attachEvent(“onCalculateEndDate”, function(task){

// My own logic goes here and updates the end date for the task

});[/code]

I’m thinking that something like that could be a good thing. I mean, even if you would add individual “schedules” to different tasks into the core functionality, one might want to add common black-lists (such as national holidays, perhaps even different one if tasks are performed in different countries) and white-lists (when it’s crunch-time and the task really needs to be completed to meet the deadline). Why not simply let us, the users, handle that logic instead?

If this seems like a realistic way forward, could it perhaps be entered into an earlier release? Perhaps even the next upcoming one…? (My guess is that this solution is less complicated for you to implement.)

Thanks,
Fred S

Hi,
thanks for the suggestion! The final design is still under consideration, and unfortunately version 3.0 won’t contain any updates on this matter.

I have the same challenge.

Any updates on this?

Do you know if 3.1 includes this, if not do you still plan on implementing this?

Thanks

Hello,
this functionality is still in plans.
Probably we’ll implement it by the next update, approximately in February-March 2015

Thanks - looking forward to it.

I’m not looking to stress you about this, but considering roughly two months has passed, I was wondering if you can say whether or not this will be in the next release?

And if so, when is it scheduled? Later this March?

Thanks,
Fred S

Hello,
the update has been released yesterday. Unfortunately, it does not includes this functionality, it’s still pending

I’m not sure what to make of the situation here. I initially asked about this seven months ago, and as I understand it, the functionality is actually planned to be added. I also came up with a solution that hopefully would make support for this easier to implement for you. (Exposing “calculateEndDate” as an event.)

Still, here we are, seven months - and several versions - later. With no way of handling per-task worktime settings.

I have no doubt your list of improvements and fixes is quite long, but considering the age of this request perhaps it would be possible to commit to a date when it will be available?

(Not sure if it makes any difference, but I am a paying customer.)

Thanks,
Fred S

Hello, I need to set worktime per task in my service. Todey, Do we have this issue in any version of DHTMLX gantt ? Thanks.

Hello Marcio,
The feature to have different worktime settings per task was added in the 4.2 version:
https://docs.dhtmlx.com/gantt/whatsnew.html#42
To use it, you need to create a custom calendar, assign it to a task, and specify the work time settings:
https://docs.dhtmlx.com/gantt/desktop__working_time.html#multipleworktimecalendars
Here is an example:

// Add custom calendar:
gantt.addCalendar({
    id: "custom"
});

// Set worktime settings for that calendar:
gantt.getCalendar("custom").setWorkTime({ date: new Date(2025, 04, 05), hours: false })

// Assign the calendar by specifying its ID in the "calendar_id" property for the "task" object:

        {
            "id": 6,
            "text": "Task #5 - custom calendar",
            "start_date": "02-04-2018",
            "duration": 4,
            "parent": 1,
            "progress": 0.25,
            "owner_id": 124,
            "calendar_id": "custom"
        },

You can also add the calendars to resources, and it will be applied to all tasks that have that resource assigned:
https://docs.dhtmlx.com/gantt/desktop__working_time.html#assigningcalendartoresource

Here are the demos:
https://snippet.dhtmlx.com/6vph6heu
https://docs.dhtmlx.com/gantt/samples/09_worktime/06_task_calendars.html
https://docs.dhtmlx.com/gantt/samples/09_worktime/07_resource_calendars.html