Save event for the Parent

4 posts, 0 answers
  1. Dan
    Dan avatar
    143 posts
    Member since:
    Nov 2017

    Posted 14 Sep 2018 Link to this post

    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?

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1749 posts

    Posted 18 Sep 2018 Link to this post

    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.
  3. Dan
    Dan avatar
    143 posts
    Member since:
    Nov 2017

    Posted 22 Sep 2018 in reply to Ivan Danchev Link to this post

    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?

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1749 posts

    Posted 25 Sep 2018 Link to this post

    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.
Back to Top