v7.3.0

EventDrag
Feature

Allows user to drag and drop events within the scheduler, to change startDate or resource assignment.

This feature is enabled by default

Customizing the drag drop tooltip

To show custom HTML in the tooltip, please see the tooltipTemplate config. Example:

features: {
    eventDrag : {
        // A minimal start date tooltip
        tooltipTemplate : ({ eventRecord, startDate }) => {
            return DateHelper.format(startDate, 'HH:mm');
        }
    }
}

Constraining the drag drop area

You can constrain how the dragged event is allowed to move by using the following configs

// Enable dragging + constrain drag to current resource
const scheduler = new Scheduler({
    features : {
        eventDrag : {
            constrainDragToResource : true
        }
    }
});

Drag drop events from outside

Dragging unplanned events from an external grid is a very popular use case. There are several demos showing you how to do this. Please see the Drag from grid demo and study the Drag from grid guide to learn more.

Drag drop events to outside target

You can also drag events outside the schedule area by setting constrainDragToTimeline to false. You should also either:

See this demo to see this in action.

Validating drag drop

It is easy to programmatically decide what is a valid drag drop operation. Use the validatorFn and return either true / false (optionally a message to show to the user).

features : {
    eventDrag : {
       validatorFn({ eventRecords, newResource }) {
           const task  = eventRecords[0],
                 valid = newResource.role === task.resource.role;

return { valid : newResource.role === task.resource.role, message : valid ? '' : 'Resource role does not match required role for this task' }; } } }

See this demo to see validation in action.

If you instead want to do a single validation upon drop, you can listen to beforeEventDropFinalize and set the valid flag on the context object provided.

  const scheduler = new Scheduler({
     listeners : {
         beforeEventDropFinalize({ context }) {
             const { eventRecords } = context;
             // Don't allow dropping events in the past
             context.valid = Date.now() <= eventRecords[0].startDate;
         }
     }
 });

Preventing drag of certain events

To prevent certain events from being dragged, you have two options. You can set draggable to false in your data, or you can listen for the beforeEventDrag event and return false to block the drag.

new Scheduler({
   listeners : {
       beforeEventDrag({ eventRecord }) {
           // Don't allow dragging events that have already started
           return Date.now() <= eventRecord.startDate;
       }
   }
})

Events that are selected, but not visually accessible, are not included in drag operations. This means that events in collapsed groups or filtered out resources are not dragged, even if they were selected prior to being collapsed or filtered out of visibility.

Useful configs and functions

Member Description
beforeEventDrag Fires before drag starts, return false to prevent
eventDragStart Fires when event drag begins
eventDrag Fires continuously during drag
eventDrop Fires when event is dropped at new position
beforeEventDropFinalize Async finalizer before drop is applied
tooltipTemplate Template for the drag tooltip

See also

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Set this to true to always copy the event on drag drop operation.

    Has a corresponding runtime alwaysCopy property.

  • Set to true to only allow dragging events within the same resource.

    Has a corresponding runtime constrainDragToResource property.

  • Set to true to only allow dragging events to different resources, and disallow rescheduling by dragging.

    Has a corresponding runtime constrainDragToTimeSlot property.

  • copyKey : 'CTRL'/'ALT'/'SHIFT'/'META'/''CTRL

    A modifier key (CTRL, SHIFT, ALT, META) that when pressed will copy an event instead of moving it. Set to empty string to disable copying. Defaults to "CTRL" which is the Ctrl-key for Windows, and Meta-key for MacOS.

    Has a corresponding runtime copyKey property.

  • copyMode : 'auto'/'assignment'/'event'auto

    Event can be copied two ways: either by adding new assignment to an existing event ('assignment'), or by copying the event itself ('event'). 'auto' mode will pick 'event' for a single-assignment mode (when event has resourceId field) and 'assignment' mode otherwise.

    Has a corresponding runtime copyMode property.

  • A CSS selector specifying elements outside the scheduler element which are valid drop targets.

  • Set to true to only allow dragging in one direction (based on initial movement)

    Has a corresponding runtime singleDirection property.

  • The this reference for the validatorFn

Properties

Properties are getters/setters or publicly accessible variables on this class
  • Set this to true to always copy the event on drag drop operation.

    Has a corresponding alwaysCopy config.

  • Set to true to only allow dragging events within the same resource.

    Has a corresponding constrainDragToResource config.

  • Set to true to only allow dragging events to different resources, and disallow rescheduling by dragging.

    Has a corresponding constrainDragToTimeSlot config.

  • copyKey : 'CTRL'/'ALT'/'SHIFT'/'META'/''CTRL

    A modifier key (CTRL, SHIFT, ALT, META) that when pressed will copy an event instead of moving it. Set to empty string to disable copying. Defaults to "CTRL" which is the Ctrl-key for Windows, and Meta-key for MacOS.

    Has a corresponding copyKey config.

  • copyMode : 'auto'/'assignment'/'event'auto

    Event can be copied two ways: either by adding new assignment to an existing event ('assignment'), or by copying the event itself ('event'). 'auto' mode will pick 'event' for a single-assignment mode (when event has resourceId field) and 'assignment' mode otherwise.

    Has a corresponding copyMode config.

  • mode : 'move'/'copy'
    READONLY

    Mode of the current drag drop operation.

  • Set to true to only allow dragging in one direction (based on initial movement)

    Has a corresponding singleDirection config.

  • isEventDrag : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of EventDrag class, or subclass thereof.

Functions

Functions are methods available for calling on the class
    • updateAssignments( )
      private
      ASYNC

      Update assignments being dragged

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    Type definitions

    id: eventDrag

    Source path

    Scheduler/feature/EventDrag.js

    Demo

    examples/basic

    Contents