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

Save event for the Parent

3 Answers 84 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Dan asked on 14 Sep 2018, 11:58 AM

I have a gantt on a page. The GanttTask object has Creator and Modifier on them and they need to be set on the client (so using javascript code).

I have attached to the save event like this

Html.Kendo().Gantt<ViewModel, DependencyViewModel>(),Name("gantt").Events(e => e.Add("onAdd").Save("onSave"))

and the javascript code

function onSave(e) {
  e.task.ModifiedBy = '@Html.Action("GetCurrentUser", "XXX")';
  e.task.ModifiedDate = new Date(Date.now());
}

When I change a task everything works as expected. However if I change a child task by changing the end date that affects also the parent I need to set the Modifier on that parent too.  

Is there an event called before updating the parents that I could use to set the Modifier ? How can I get the parents that are going to be updated in the onSave event?

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 18 Sep 2018, 06:52 AM
Hello Dan,

There is no separate event that fires for the parent task when modifying a child task. However you can get the parent task from the save event handler that fires for the child task, as demonstrated below:
function onSave(e) {
  e.task.ModifiedBy = '@Html.Action("GetCurrentUser", "XXX")';
  e.task.ModifiedDate = new Date(Date.now());
   
  var parentTaskId = e.task.parentId;
  var data = e.sender.dataSource.data();
  var parentElem = "";
   
  for(var i = 0; i < data.length; i++) {
    if(data[i].id == parentTaskId) {
      parentElem = $(".k-gantt-treelist tr[data-uid=" + data[i].uid + "]");
    }
  }
   
  if(parentElem) {
    var parentTask = e.sender.dataItem(parentElem);
    console.log(parentTask);
  }
}



Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 22 Sep 2018, 12:12 PM

Hi Ivan,

Thank you for the modality of getting the parent. Just to be clear I still have a question: Is there a way to know if the parent is also going to be affected by the changes of the child?

0
Ivan Danchev
Telerik team
answered on 25 Sep 2018, 02:46 PM
Hi Dan,

No, information on whether the parent task will get affected is not available. In the save event handler you can see the changes to the child task, but the parent task's fields haven't been updated yet (this happens internally at later point).

Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Gantt
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Ivan Danchev
Telerik team
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or