search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to listen or get the key event in scheduler e.g. delete key

Asked by juni
10 years ago.

For example, after select an event in scheduler, once the user press DEL key from the keyboard, the event will be deleted.
This shortcut is much faster than when you use context menu.

Thanks,

  • juni
Answer posted by Dan Letecky [DayPilot]
10 years ago.

The Scheduler doesn't contain any element that can get focus. You can detect the Delete key for the whole page using the following code:

<script type="text/javascript">
$(document).keyup(function (e) {
    if (e.keyCode == 46) {
      var firstSelected = dp.multiselect.events()[0];
      dp.commandCallBack("delete", { e: firstSelected });
    }
});

On the server side (ASP.NET MVC):

class Dps : DayPilotScheduler
{
  // ...
  protected override void OnCommand(CommandArgs e)
  {
      switch (e.Command)
      {
          case "delete":
              string id = (string)e.Data["e"]["id"];
              new EventManager(Controller).EventDelete(id);
              Update(CallBackUpdateType.EventsOnly);
              break;
      }
  }
}
Comment posted by juni
10 years ago.

Thanks Dan, it works properly now.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.