Update Tasks in GanttChart

2 Answers 21 Views
DatePicker GanttView GridView TimeLine
Leire
Top achievements
Rank 1
Iron
Iron
Leire asked on 25 May 2022, 07:37 AM

Hello,

I want to know if its possible to update Gantt Tasks when you change a Start Date or End Date from the Grid View part. For example, if I delay Proptotype Task, all the task behind should be delayed the same time as Prototype.

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 27 May 2022, 04:13 PM

Hello Leire,

Thank you for the provided image.

What I can suggest for accomplishing this requirement would be to handle the TaskEditing and TaskEdited events.

In the TaskEditing event handler, you can preserve the previous End of the task and in the TaskEdited event, you can calculate whether the change should modify the rest of the tasks. If that is the case, you can iterate over them and modify their Start and/or End times.

        private DateTime oldTaskEnd;

        private void OnTaskEditingCommandExecuted(object obj)
        {
            var args = obj as TaskEditingEventArgs;
            var task = args.Task;
            this.oldTaskEnd = args.Task.End;
        }

        private void OnTaskEditedCommandExecuted(object obj)
        {
            var args = obj as TaskEditedEventArgs;
            var updatedTask = args.Task;
            if (this.oldTaskEnd < updatedTask.End)
            {
                var tasks = this.GanttTasks.SelectMany(t => t.Children);
                foreach (var task in tasks)
                {
                    if (task.Start > this.oldTaskEnd)
                    {
                        task.Start = task.Start.Add(updatedTask.End - this.oldTaskEnd);
                        task.End = task.End.Add(updatedTask.End - this.oldTaskEnd);
                    }
                }
            }
        }

I've also prepared a small sample project to demonstrate this in action. You can change the End time of the "Design public API" task and notice that if you add a few days/hours to it, the rest of the tasks will be updated accordingly.

Please give this a try and let me know if such an approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Leire
Top achievements
Rank 1
Iron
Iron
answered on 01 Jun 2022, 08:40 AM
It did work for me, thanks for the sample project Dylan!
Tags
DatePicker GanttView GridView TimeLine
Asked by
Leire
Top achievements
Rank 1
Iron
Iron
Answers by
Dilyan Traykov
Telerik team
Leire
Top achievements
Rank 1
Iron
Iron
Share this question
or