DHTMLX / gantt

GPL version of Javascript Gantt Chart
https://dhtmlx.com/docs/products/dhtmlxGantt/
GNU General Public License v2.0
1.44k stars 320 forks source link

The progress bar cannot be updated automatically, after modifying the start and end times #79

Closed zhouqunfang closed 11 months ago

zhouqunfang commented 2 years ago

The progress bar cannot be updated automatically, after modifying the start and end times

ArtiBorisevich commented 2 years ago

Hello, As I understood your question correctly, you want to update the progress bar of the task after its duration changes (for example, if the duration is 2 days and progress is 50%, so after changing the duration to 4 days, the progress of the task should change to 25%). To get this functionality, you can use onBeforeTaskChanged event: https://docs.dhtmlx.com/gantt/api__gantt_onbeforetaskchanged_event.html ; In the beginning, you need to use getTask method that will return the current task object (with new data of the dragged position): https://docs.dhtmlx.com/gantt/api__gantt_gettask.html ; To calculate new progress, you need to divide original progress by current duration and multiply by previous duration of the task:

 let currentTask = gantt.getTask(id);
 let originalProgress = currentTask.progress;
 let progressStep = originalProgress / currentTask.duration;
 let newProgress = progressStep * task.duration;
 currentTask.progress = newProgress;
 gantt.updateTask(id);

and update the task by updateTask method: https://docs.dhtmlx.com/gantt/api__gantt_updatetask.html ; The same logic will be applied to onLightboxSave event, only the getTask method will return the original task object (values aren't applied to the task object yet): https://docs.dhtmlx.com/gantt/api__gantt_onlightboxsave_event.html ; Please check the following snippet: https://snippet.dhtmlx.com/lpitgh8t