4

I've created a Kendo Scheduler that binds to a remote data source. The remote datasource is actually a combination of two separate data sources. This part is working okay.

Question is... is there any way to prevent certain events from being destroyed?

I've stopped other forms of editing by checking a certain field in the event's properties and calling e.preventDefault() on the edit, moveStart and resizeStart events if it should be read-only. This works fine, but I can't prevent deletes.

Any suggestions greatly appreciated.

Mat
  • 1,668
  • 4
  • 23
  • 40

3 Answers3

5

Just capture the remove event and process it as you have with the edit, moveStart, and reviseStart events. You should see a remove event option off the kendo scheduler. I can see it and capture it in version 2013.3.1119.340.

  • Yup. I was being dumb... I was looking for a destroy event and missed the remove event completely. – Mat Jan 28 '14 at 08:47
  • 1
    Having said that... capturing the remove event isn't perfect as it occurs after the popup confirmation -- this gives the user the impression that the event CAN be deleted. Ideally I wouldn't want to display the confirmation for these 'read-only' events. – Mat Jan 28 '14 at 09:19
  • Mat, did you ever have any luck preventing the confirmation popup? – wulimaster Apr 24 '14 at 16:24
  • 2
    For future visitors, to achieve this I finally removed `.k-event-delete` and `.k-resize-handle` elements from readonly-events (do this in `dataBound` event). – OlivierH Jul 31 '14 at 14:58
  • http://stackoverflow.com/questions/29074344/handle-destroy-event-in-kendo-scheduler any solution to this issue ? – Swaraj Mar 26 '15 at 12:32
4

I think better way is to prevent user from going to remove event in the first place. Handling the remove event still has its validity as you can delete event for example by pressing "Delete" key).

In example below I'm assuming event has custom property called category and events with category equal to "Holiday" can't be deleted.

remove: function(e)
{
  var event = e.event;
  if (event.category === "Holiday")
  {
    e.preventDefault();
    e.stopPropagation();
  }
},
dataBound: function(e)
{
  var scheduler = e.sender;
  $(".k-event").each(function() {
    var uid = $(this).data("uid");
    var event = scheduler.occurrenceByUid(uid);
    if (event.category === "Holiday")
    {
      // use .k-event-delete,.k-resize-handle if you want to prevent also resizing
      $(this).find(".k-event-delete").hide();
    }
  });
},
edit: function (e) {
   var event = e.event;
   if (event.category === "Holiday")
   {
     e.container.find(".k-scheduler-delete").hide();
   }
}
Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
2

FYI, you can do this...

@(Html.Kendo().Scheduler<ScheduledEventViewModel>()
    .Name("scheduler")
    .Editable(e => e.Confirmation(false))
)

which will deactivate the default confirmation prompt for the scheduler. Then you can do your own prompt on items you want.

There is also a

.Editable(e => e.Destroy(false))

that you can do to remove the X on the event window. This particular example would remove it for all of the events, but there might be a way to remove it for specific ones.

Scottie
  • 11,050
  • 19
  • 68
  • 109