Wrong default date rounding on Task drag when using different Zoom level


#1

Hi,

during a task drag, there is a default mecanism that rounds the date to the closest (?) date after the onBeforeTaskDrag event.

This is ok with a zoom level where grid corresponds to days.

But if there is a higher zoom level ( weeks ), the tasks dates are correctly changed during the drag, but when the drop happens, the dates are rounded to fit the closest grid, which corresponds not to a day rounding, but to a week rounding.

I can’t find a way to disable or modify this behavior.

There is a mention of this topic on this page : https://docs.dhtmlx.com/gantt/desktop__dnd.html but I did not manage to get something working out of it.

Extract of the comment :


I have found that the example works wrong on “non-standard” zoom level.

The reason is - children dates are rounded not to the gantt.config.duration_unit/step, but to the current unit/step which results in children sticking to the current grid even if the parent task was moved by a diff less than one current unit.
I.e. if you have gantt.config.duration_unit = day, but current grid has unit/step = 1 week, if you move the parent task in the middle of the week cell, its children start dates are moved to the next or current week start date which is obviously wrong.

Proper example should be:
child.start_date = gantt.roundDate({date: child.start_date,unit: gantt.config.duration_unit,step: gantt.config.duration_step});


Can you help me with a sample of code to fix this beahavior ?


#2

Hello Julien,
You can disable the round_dnd_dates parameter so that Gantt won’t round the dates to the nearest scale:
https://docs.dhtmlx.com/gantt/api__gantt_round_dnd_dates_config.html

However, we are aware of the issue that if you drag a project with its subtasks in the year or month view, the distance between tasks will not be saved:
https://snippet.dhtmlx.com/5/79bf505b1
Unfortunately, we don’t have a fix for that.