v7.3.0
SupportExamplesFree Trial

EventCopyPaste
Feature

Allow using Ctrl/Cmd+C, Ctrl/Cmd+X and Ctrl/Cmd+V to copy/cut and paste events.

This feature also adds entries to the EventMenu for copying & cutting (see example below for how to configure) and to the ScheduleMenu for pasting.

You can configure how a newly pasted record is named using generateNewName.

targetElement.innerHTML = '<p>Copy/cut and paste events using keyboard shortcuts or context menu:</p>'; const scheduler = new Scheduler({ appendTo : targetElement, // makes scheduler as high as it needs to be to fit rows autoHeight : true, startDate : new Date(2021, 1, 6), endDate : new Date(2021, 1, 20), viewPreset : 'dayAndWeek', columns : [ { field : 'name', text : 'Name', width : 100 } ], resources : [ { id : 1, name : 'Bernard' }, { id : 2, name : 'Bianca' } ], events : [ { id : 1, resourceId : 1, name : 'Interview', startDate : '2021-02-06', endDate : '2021-02-07' }, { id : 2, resourceId : 1, name : 'Press meeting', startDate : '2021-02-08', endDate : '2021-02-09' }, { id : 3, resourceId : 2, name : 'Audition', startDate : '2021-02-07', endDate : '2021-02-09' }, { id : 4, resourceId : 2, name : 'Script deadline', startDate : '2021-02-11', endDate : '2021-02-11' } ] });

If you want to highlight the paste location when clicking in the schedule, consider enabling the ScheduleContext feature.

When used with Scheduler Pro, pasting will bypass any constraint set on the event to allow the copy to be assigned the targeted date.

This feature is enabled by default.

Customize menu items

See EventMenu and ScheduleMenu for more info on customizing the menu items supplied by the feature. This snippet illustrates the concept:

// Custom copy text + remove cut option from event menu:
const scheduler = new Scheduler({
    features : {
        eventMenu : {
            items : {
                copyEvent : {
                    text : 'Copy booking'
                },
                cutEvent  : false
            }
        }
    }
});

Keyboard shortcuts

The feature has the following default keyboard shortcuts:

Keys Action Action description
Ctrl+C copy Copies selected event(s) into the clipboard.
Ctrl+X cut Cuts out selected event(s) into the clipboard.
Ctrl+V paste Insert copied or cut event(s) from the clipboard.

Please note that Ctrl is the equivalent to Command and Alt is the equivalent to Option for Mac users

For more information on how to customize keyboard shortcuts, please see our guide.

Multi assigned events

In a Scheduler that uses single assignment, copying and then pasting creates a clone of the event and assigns it to the target resource. Cutting and pasting moves the original event to the target resource.

In a Scheduler using multi assignment, the behaviour is slightly more complex. Cutting and pasting reassigns the event to the target, keeping other assignments of the same event intact. The behaviour for copying and pasting is configurable using the copyPasteAction config. It accepts two values:

  • 'clone' - The default, the event is cloned and the clone is assigned to the target resource. Very similar to the behaviour with single assignment (event count goes up by 1).
  • 'assign' - The original event is assigned to the target resource (event count is unaffected).

This snippet shows how to reconfigure it:

const scheduler = new Scheduler({
    features : {
        eventCopyPaste : {
            copyPasteAction : 'assign'
        }
    }
});
Copying multiple assignments of the same event will always result in all but the first assignment being removed on paste, since paste targets a single resource and an event can only be assigned to a resource once.

Native/shared clipboard

If you have multiple Schedulers (or other Bryntum products) on the same page, they will share clipboard. This makes it possible to copy and paste between different Scheduler instances. It is also possible to use the native Clipboard API if it is available and if you set useNativeClipboard to true.

Regardless of native clipboard availability, copy-pasting "outside" of the current Scheduler instance will convert the copied events to a string. When pasting, the string will then be parsed back into events. In case of usage of the native Clipboard API, this means it is possible to copy and paste events between completely different applications.

To configure the fields that is converted and parsed from the copied string value, please see the eventToStringFields config.

Useful configs and functions

Member Description
beforeCopy Fires before copy, return false to prevent
copy Fires when events are copied
beforePaste Fires before paste, return false to prevent
paste Fires when events are pasted

See also

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • The field to use as the name field when updating the name of copied records

  • By default, pasting of multiple events will spread out according to the pattern it was copied. Set to false to paste into the same resource and same date.

  • Configure which sources $name this class allows pasting model data from. Accepts string or array. Unspecified accepts all. If source is not accepted, it will try to use the string value instead.

  • Set this to true to use native Clipboard API if it is available

  • If true this prevents cutting and pasting. Will default to true if CellEdit feature is disabled. Set to false to prevent this behaviour.

  • The format a copied date value should have when converted to a string. To learn more about available formats, check out DateHelper docs.

  • Default keyMap configuration: Ctrl/Cmd+c to copy, Ctrl/Cmd+x to cut and Ctrl/Cmd+v to paste. These keyboard shortcuts require a selection to be made.

  • Internal listeners, that cannot be removed by the user.

  • The widget which this plugin is to attach to.

    Has a corresponding runtime client property.

  • Set to false to disable localization of this object.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isClipboardable : Booleantrue
    READONLY
    static
    ADVANCED
    Clipboardable
    Identifies an object as an instance of Clipboardable class, or subclass thereof.
  • isEventCopyPaste : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
  • isEvents : Booleantrue
    READONLY
    static
    ADVANCED
    Events
    Identifies an object as an instance of Events class, or subclass thereof.
  • isLocalizable : Booleantrue
    READONLY
    static
    ADVANCED
    Localizable
    Identifies an object as an instance of Localizable class, or subclass thereof.
  • properties : Object
    internal
    static
    CopyPasteBase

    A class property getter for the default values of internal properties for this class.

  • emptyArray : Array
    internal
    READONLY
    CopyPasteBase

    An empty array that can be used as a default value.

  • emptyObject : Object
    internal
    READONLY
    CopyPasteBase

    An empty object that can be used as a default value.

  • isCopyPasteBase : Booleantrue
    READONLY
    ADVANCED
    CopyPasteBase
    Identifies an object as an instance of CopyPasteBase class, or subclass thereof.
  • isEventCopyPaste : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
  • isInstancePlugin : Booleantrue
    READONLY
    ADVANCED
    CopyPasteBase
    Identifies an object as an instance of InstancePlugin class, or subclass thereof.
  • clipboard : Object
    private
    READONLY
    Clipboardable

    Gets the current shared Clipboard instance

  • A method used to generate the name for a copy-pasted record. By defaults appends "- 2", "- 3" as a suffix. Override it to provide your own naming of pasted records.

    Has a corresponding generateNewName config.

  • config : Object
    READONLY
    ADVANCED
    CopyPasteBase

    Returns a copy of the full configuration which was used to configure this object.

  • This property is set to true before the constructor returns.

  • isDestroying : Boolean
    READONLY
    ADVANCED
    CopyPasteBase

    This property is set to true on entry to the destroy method. It remains on the objects after returning from destroy(). If isDestroyed is true, this property will also be true, so there is no need to test for both (for example, comp.isDestroying || comp.isDestroyed).

  • client : Widget
    READONLY
    ADVANCED
    CopyPasteBase

    The Widget which was passed into the constructor, which is the Widget we are providing extra services for.

    Has a corresponding client config.

  • Get the global LocaleHelper

  • Get the global LocaleManager

Functions

Functions are methods available for calling on the class
  • onClassMixedIn( )
    internal
    static
    CopyPasteBase

    This optional class method is called when a class is mixed in using the mixin() method.

  • initClass( )
    static
    ADVANCED
    CopyPasteBase

    Registers this class type with its Factory

  • Clears the clipboard data

  • Internal function used to hook destroy() calls when using thisObj

  • Internal function used restore hooked destroy() calls when using thisObj

  • doDestroy( )
    internal
    Events

    Auto detaches listeners registered from start, if set as detachable

  • once( )
    private
    Events

    Internal function used to run a callback function after an event is triggered

  • Removes all listeners registered to this object by the application.

  • This will merge a feature's (subclass of InstancePlugin) keyMap with it's client's keyMap.

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
id: eventCopyPaste

Source path

Scheduler/feature/EventCopyPaste.js

Contents