Need to calculate the targetIndex in onAfterTaskDrag with varying row heights

I’m encountering an issue with calculating the targetIndex in the onAfterTaskDrag event when row heights vary. Currently, I’m using the following code:

const target_index = Math.floor(y_pos / gantt.config.row_height);
let target_task = gantt.getTaskByIndex(target_index);

This approach works well when all rows have the same height. However, in my use case, some rows have different heights due to custom styling or expanded tasks, making it difficult to calculate the target_index based on gantt.config.row_height.

I need to find a way to dynamically determine the correct targetedIndex when row heights are no longer uniform.

Has anyone encountered this issue, or could you suggest an alternative method to achieve this?

Any help or guidance would be greatly appreciated!

Hello Jai,
The onAfterTaskDrag event doesn’t have the target index as the task is dragged only horizontally. Are you trying to use the custom implementation that allows to vertically reorder tasks? If that is the case, you need to customize how everything works there as the implementation was created when Gantt didn’t have the feature to set different task row height.

Here is an example that can help you to start implementing your solution:
https://snippet.dhtmlx.com/94z2bqwq

Please note that it is not a final solution, only an example of the implementation. So, it may not work correctly in all possible scenarios.

In the future, the dev team will add that feature to Gantt, but I cannot give you any ETA.

1 Like