Add an event in Kendo Scheduler using context menu and Kendo window

2 posts, 1 answers
  1. Varinder
    Varinder avatar
    5 posts
    Member since:
    Apr 2020

    Posted 15 Apr Link to this post

    Hi guys,

    What I have done is I have added a Context Menu with option Create Event (gets visible after mouse right click on scheduler) .
    Now when User clicks on Create event then opening Kendo Window. In this I have two text boxes for Date and Time. 
    Here what I want is I need Date and Time from Scheduler where user has clicks right of mouse.
    For Example
    If user right clicks on any cell of 15th date of scheduler at 10 am then text boxes should get filled with 15-04-2020 and 10:00 am respectively
    Similarly, If user right clicks on any cell of 18th date of scheduler at 01 pm then text boxes should get filled with 18-04-2020 and 01:00 pm respectively and so on.
    Here is Code Snippet

    Also I have attached screen shots.

    Please help.

  2. Answer
    Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1201 posts

    Posted 17 Apr Link to this post

    Hi Varinder,

    Here is what I would suggest to you in order to achieve the desired result:

    - use a global variable where to keep the start and end Date objects:

    var start = null;
    var end = null;

    - Within the ContextMenu open event, obtain the slot data:

    open: function (e) {
      var menu = e.sender;
      var target = $(e.target);
      var text = target.hasClass("k-event") ? "" : " ";
      var scheduler = $("#scheduler").getKendoScheduler();
      var slot = scheduler.slotByElement(target);
      
      start = slot.startDate;
      end = slot.endDate;
    
      menu.remove(".myClass");
      menu.append([{text: text, cssClass: "myClass" }]);
    }

    Within the open event of the Window assign the appropriate values to the inputs:

    open: function (e) {
      var windowElement = e.sender.element;
      var dateInput = windowElement.find("#date");
      var timeInput = windowElement.find("#time");
      var startTime = start.toLocaleTimeString();
      var startDate = start.toDateString();
      
      dateInput.val(startDate);
      timeInput.val(startTime);
    
      $("body").addClass("ob-no-scroll");
    },

    Here you could find a modified version of the Dojo sent:

    http://dojo.telerik.com/ALoVexIk/5

    Regards,
    Veselin Tsvetanov
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top