This is a migrated thread and some comments may be shown as answers.

Custom task Update

2 Answers 135 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 28 Jan 2020, 01:16 PM

Hello,
When a child's task start/stop date is changed, parent task is changed as well.
I need to disable this behavior. I want a parent task start/stop date to be changed only directly.
I tried this:

protected void RadGantt1_TaskUpdate(object sender, Telerik.Web.UI.Gantt.TaskEventArgs e)
{  
  while (((List<Telerik.Web.UI.Gantt.ITask>)e.Tasks).Count>1)
  {
    ((List<Telerik.Web.UI.Gantt.ITask>)e.Tasks).RemoveAt(0);
  }
}

 

This works, but for all changes. So when % of completed is changed on a child, this is not changed on the parent task.
I need to know, what is the change when TaskUpdate is triggered on the server. 
Or another solution.
Thank you.

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 31 Jan 2020, 08:48 AM

Hello Igor,

In the TaskUpdate event, you can access the modified tasks, and based on their ID property, you can get the original task from the Gantt: 

protected void RadGantt1_TaskUpdate(object sender, Telerik.Web.UI.Gantt.TaskEventArgs e)
{
    var gantt = sender as RadGantt;
    foreach (var newTask in e.Tasks)
    {
        var originalTask = gantt.GetAllTasks().FirstOrDefault(t => t.ID == newTask.ID);
        // compare original and modified tasks properties...
    }
}

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 31 Jan 2020, 11:51 AM

Thank you for your answer.
Unfortunately, in my case is gantt.GetAllTasks() empty. 
For now, I created a dirty workaround. I will add needed info to the task name and then removing it when needed.

Client:

function OnClientTaskResizeEnd(sender, args)
    {
      var parent = sender.get_allTasks().filter(function (item)
      {
        return args.get_task().parentId == item._data.id
      });
 
      if (parent.length > 0)
      {
        //Is child taks outside parent boundaries?
        if (args.get_start() < parent[0]._data.start || args.get_end() > parent[0]._data.end)
        {
          args.set_cancel(true);
          return;
        }
        else
        {
          args.get_task().title = "#CHANGE;" + encodeURIComponent(args.get_task().title) + ";RESIZE"
        }
      }
    }
 
    function OnClientTaskMoveEnd(sender, args)
    {
      parent = sender.get_allTasks().filter(function (item)
      {
        return args.get_task().parentId == item._data.id
      });
 
      if (parent.length > 0)
      {
          var changeDiff = args.get_task().start - args.get_start();
          var startDiff = args.get_task().start - parent[0]._data.start;
          var endDiff = args.get_task().end - parent[0]._data.end;
 
          //Is child taks outside parent boundaries?
          if (startDiff - changeDiff < 0 || endDiff - changeDiff > 0)
          {
            args.set_cancel(true);
            return;
          }
          else
          {
            args.get_task().title = "#CHANGE;" + encodeURIComponent(args.get_task().title) + ";MOVE"
          }
        }
    }

Server:

protected void RadGantt1_TaskUpdate(object sender, Telerik.Web.UI.Gantt.TaskEventArgs e)
    {    
     var changedTask = e.Tasks.FirstOrDefault(task => task.Title.StartsWith("#CHANGE;"));
      if (changedTask != null)
      { //Remove parent tasks if needed
        while (((List<Telerik.Web.UI.Gantt.ITask>)e.Tasks).Count > 0 && ((List<Telerik.Web.UI.Gantt.ITask>)e.Tasks)[0] != changedTask )
        {
          ((List<Telerik.Web.UI.Gantt.ITask>)e.Tasks).RemoveAt(0);
        }
      }
    }

 

On DB update event:

public void UpdateTasksDS(Int32? PARENT_ID, Int32 ORDER_ID, string NAME, DateTime START_DATE, DateTime END_DATE, decimal PERCENT_COMPLETED, bool EXPANDED, bool SUMMARY, Int32 ID)
    {
      if (NAME.StartsWith("#CHANGE;"))
      {
        NAME = Uri.UnescapeDataString(NAME.Split(';')[1]);
      }
// Rest of code...
}

This needs to be done for the custom task window also.

 

Tags
Gantt
Asked by
Igor
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Igor
Top achievements
Rank 1
Share this question
or