Prevent automatic update of parent task values in the gantt grid


#1

Hi

I have the following situation on the gantt chart:

When I change the estimated time for the ‘Subtask’ task, the estimated time for the parent of that task is automatically changed as well. For projects I don’t mind this, but for the parent task ‘Top task’ I would need to prevent this from happening. I know that I can use something like this to change the value manually, when the grid line is redrawn:

{name: ‘estimated’, label: ‘Estimated time’, width:68, align: ‘center’, resize: true, editor: estimatedEditor,
template: (task) => {
return xxx;
}
},

However the estimatedEditor is mapped to the estimated_hours value (task.estimated_hours) and when the template function is called for the ‘Top task’, this value is already changed - this means I can’t really find out how it was changed, prevent the change and return the old value. Is there some simple way how to achieve this?

Thank you very much

Ondrej


#2

Hello Ondrej,
Gantt doesn’t watch custom properties, so it depends on the logic that you use and the Gantt configuration.
I have the following example where a custom property(money) is added for each task. For project tasks, that value is calculated, but you can manually change it, and then Gantt won’t calculate it:
http://snippet.dhtmlx.com/5/4f81ac4e3

If that doesn’t help you, please, add your Gantt configuration in the following snippet and make sure that the issue is reproduced there:
https://snippet.dhtmlx.com/38ee1b370
Then, click on the Share button and send me the link.
Or send me a ready demo with all the necessary Javascript and CSS files so that I can reproduce the issue locally.


#3

Hi Ramil,

thank you very much for your answer. Let’s continue with your example:
https://snippet.dhtmlx.com/5/235d97583

I just added inline editor for money. When you first load the page (and the gantt), after first render everything works correctly, i.e. projects have the right money value (calculated as a sum of all the money values of their children). However when I change the value of one of the child tasks (e.g. Task #1), value of the parent is not recalculated, because the code in the anonymous template function is not triggered. It doesn’t matter if I change the money value using the lightbox or the inline editor.

So my question is: when I’m using this manual calculation of the project money value, what would be the best procedure to update this value in case one of the child tasks is changed?

Thank you very much

Ondrej


#4

Hello Ondrej,
Sorry, I forgot to remove a part of the code that assigns the money property.

When you change the money property from the lightbox, then click on the Save button, Gantt repaints all visible tasks, and that includes parent tasks.
If you do that with the inline editor, you need to manually repaint parent tasks. The easiest way to do that is to use the onSave event handler:
https://docs.dhtmlx.com/gantt/desktop__inline_editors_ext.html
Here is the updated snippet:
http://snippet.dhtmlx.com/5/9ece83f5b


#5

Hi Ramil,

thank you for your help. It worked.

Have a nice day

Ondrej