Clipboard in Angular Schedule component

24 Dec 202424 minutes to read

The Clipboard functionality in the Syncfusion Schedule control enhances scheduling efficiency by enabling users to cut, copy, and paste appointments with ease. This feature is especially beneficial for those managing multiple appointments, as it eliminates the need for repetitive data entry and allows users to quickly adjust their schedules without hassle.
To activate the clipboard feature in the scheduler, simply set the allowClipboard property to true.

Note: The allowKeyboardInteraction property must be true for proper functionality of the clipboard feature.

Cut, copy and paste using keyboard

The Syncfusion Schedule control supports keyboard shortcuts to streamline the process of managing appointments.

These keyboard shortcuts enable users to efficiently manage their schedules:

Operation Shortcut Description
Copy Ctrl+C Duplicate appointments to streamline the scheduling process.
Cut Ctrl+X Move appointments to a new time slot without duplicates.
Paste Ctrl+V Place copied or cut appointments into the desired time slot.

To use these shortcuts, simply click on the appointment and press Ctrl+C to copy or Ctrl+X to cut. To paste the copied or cut appointment, click on the desired time slot and press Ctrl+V

<ejs-schedule #scheduleObj height='550px' [selectedDate]="selectedDate" [allowResizing]="allowResizing"
    [allowDragAndDrop]="allowDragDrop" [eventSettings]="eventSettings" [allowClipboard]="true" [showQuickInfo]="false">
</ejs-schedule>
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ScheduleModule } from '@syncfusion/ej2-angular-schedule'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { ContextMenuModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { extend } from '@syncfusion/ej2-base';
import {
    EventSettingsModel, DayService, WeekService, WorkWeekService, MonthService, AgendaService, ScheduleComponent, MonthAgendaService
} from '@syncfusion/ej2-angular-schedule';
import { scheduleData } from './datasource';

@Component({
    imports: [
        ScheduleModule,
        ButtonModule,
        ContextMenuModule
    ],
    standalone: true,
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService, MonthAgendaService],
    styleUrls: ['./index.css'],
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild('scheduleObj')
    public scheduleObj?: ScheduleComponent;
    public allowResizing: Boolean = false;
    public allowDragDrop: Boolean = false;
    public selectedDate: Date = new Date(2024, 1, 15);
    public eventSettings: EventSettingsModel = { dataSource: <Object[]>extend([], scheduleData, undefined, true) };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Note: For Mac users, use Cmd instead of Ctrl for copy, cut, and paste operations.

Cut, copy, and paste using context menu

You can programmatically manage appointments by using the public methods cut, copy, and paste. These methods allow you to perform the same actions as the context menu or external buttons.

Utilize these public methods to manage appointments programmatically in Syncfusion Schedule control:

Method Parameters Description
copy None Duplicate the selected appointment for reuse.
cut None Remove the selected appointment from its current slot for moving.
paste targetElement (Scheduler’s work-cell) Insert the copied or cut appointment into the specified time slot.

By using these methods, you can programmatically cut, copy, and paste appointments in the scheduler, providing more control over the appointment management process.

<ejs-schedule #scheduleObj height='550px' [selectedDate]="selectedDate" [allowResizing]="allowResizing"
    [allowDragAndDrop]="allowDragDrop" [allowClipboard]="true" [showQuickInfo]="false" [eventSettings]="eventSettings">
</ejs-schedule>
<ejs-contextmenu #menuObj cssClass='schedule-context-menu' target='.e-schedule' [items]='menuItems'
    (beforeOpen)='onContextMenuBeforeOpen($event)' (select)='onMenuItemSelect($event)'></ejs-contextmenu>
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ScheduleModule } from '@syncfusion/ej2-angular-schedule'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { ContextMenuModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { extend, closest, isNullOrUndefined, remove } from '@syncfusion/ej2-base';
import {
    EventSettingsModel, DayService, WeekService, WorkWeekService, MonthService, AgendaService, ScheduleComponent, MonthAgendaService
} from '@syncfusion/ej2-angular-schedule';
import { ContextMenuComponent, MenuItemModel, BeforeOpenCloseMenuEventArgs, MenuEventArgs } from '@syncfusion/ej2-angular-navigations';
import { scheduleData } from './datasource';

@Component({
    imports: [
        ScheduleModule,
        ButtonModule,
        ContextMenuModule
    ],
    standalone: true,
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService, MonthAgendaService],
    styleUrls: ['./index.css'],
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild('scheduleObj') public scheduleObj!: ScheduleComponent;
    @ViewChild('menuObj') public menuObj!: ContextMenuComponent;
    public allowResizing: Boolean = false;
    public allowDragDrop: Boolean = false;
    public selectedDate: Date = new Date(2024, 1, 15);
    public eventSettings: EventSettingsModel = { dataSource: <Object[]>extend([], scheduleData, undefined, true) };
    public selectedTarget!: Element;
    public targetElement!: HTMLElement;
    public menuItems: MenuItemModel[] = [
        { text: 'Cut Event', iconCss: 'e-icons e-cut', id: 'Cut' },
        { text: 'Copy Event', iconCss: 'e-icons e-copy', id: 'Copy' },
        { text: 'Paste', iconCss: 'e-icons e-paste', id: 'Paste' }
    ];

    public onContextMenuBeforeOpen(args: BeforeOpenCloseMenuEventArgs): void {
        const newEventElement: HTMLElement = document.querySelector('.e-new-event') as HTMLElement;
        if (newEventElement) {
            remove(newEventElement);
        }
        this.scheduleObj.closeQuickInfoPopup();
        this.targetElement = args.event.target as HTMLElement;
        if (closest(this.targetElement, '.e-contextmenu')) {
            return;
        }
        this.selectedTarget = closest(this.targetElement, '.e-appointment,.e-work-cells,' +
            '.e-vertical-view .e-date-header-wrap .e-all-day-cells,.e-vertical-view .e-date-header-wrap .e-header-cells');
        if (isNullOrUndefined(this.selectedTarget)) {
            args.cancel = true;
            return;
        }
        if (this.selectedTarget.classList.contains('e-appointment')) {
            this.menuObj.showItems(['Cut', 'Copy'], true);
            this.menuObj.hideItems(['Paste'], true);
        } else {
            this.menuObj.showItems(['Paste'], true);
            this.menuObj.hideItems(['Cut', 'Copy'], true);
        }
    }

    public onMenuItemSelect(args: MenuEventArgs): void {
        const selectedMenuItem: string = args.item.id as string;
        switch (selectedMenuItem) {
            case 'Cut':
                this.scheduleObj.cut([this.selectedTarget] as HTMLElement[]);
                break;
            case 'Copy':
                this.scheduleObj.copy([this.selectedTarget] as HTMLElement[]);
                break;
            case 'Paste':
                this.scheduleObj.paste(this.targetElement);
                break;
        }
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Modifying content before pasting

You can modify the content of an appointment before pasting it by using beforePaste event accessing the appointment details and making necessary changes.

The following example demonstrates how to seamlessly copy and paste content from a grid to a scheduler. To do this, follow these steps:

  1. Select an Item: Click on an item in the grid.
  2. Copy the Details: Press Ctrl + C to copy the selected event details.
  3. Choose a Time Slot: Click on the desired time slot in the scheduler.
  4. Paste the Details: Press Ctrl + V to paste the copied appointment details into the selected time slot.

In this example, the beforePaste event can be utilized to intercept the event details before they are pasted. This allows you to modify the content as needed. Such modifications could include adjusting the time, adding notes, or altering other specifics of the appointment.

Note: Ensure that the field mapping matches with the fields in the scheduler.

<div class="schedule-container">
    <ejs-schedule #scheduleObj height='550px' [selectedDate]="selectedDate" [allowResizing]="allowResizing"
        [allowDragAndDrop]="allowDragDrop" [eventSettings]="eventSettings" [allowClipboard]="true"
        [showQuickInfo]="false" (beforePaste)="onBeforePaste($event)">
    </ejs-schedule>

    <ejs-grid id="Grid" #gridObj [dataSource]="gridData" width="40%" height="450px" cssClass="drag-grid"
        [allowSelection]="true">
        <e-columns>
            <e-column field="OrderID" headerText="Order ID" textAlign="Right" width="90"></e-column>
            <e-column field="CustomerID" headerText="Customer ID" width="100"></e-column>
            <e-column field="ShipCity" headerText="Ship City" width="100"></e-column>
            <e-column field="ShipName" headerText="Ship Name" width="130"></e-column>
            <e-column field="OrderDate" headerText="Order Date" type="date" format="yMd" width="100"></e-column>
        </e-columns>
    </ejs-grid>
</div>
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { BeforePasteEventArgs, ScheduleModule } from '@syncfusion/ej2-angular-schedule'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { ContextMenuModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { extend } from '@syncfusion/ej2-base';
import {
    EventSettingsModel, DayService, WeekService, WorkWeekService, MonthService, AgendaService, ScheduleComponent, MonthAgendaService
} from '@syncfusion/ej2-angular-schedule';
import { scheduleData } from './datasource';
import { GridModule } from '@syncfusion/ej2-angular-grids'


interface ScheduleData {
    Id: string;
    Subject: string;
    StartTime: string;
    EndTime: string;
    Location: string;
    Description: string
}

@Component({
    imports: [
        ScheduleModule,
        ButtonModule,
        ContextMenuModule,
        GridModule
    ],
    standalone: true,
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService, MonthAgendaService],
    styleUrls: ['./index.css'],
    encapsulation: ViewEncapsulation.None
})
export class AppComponent {
    @ViewChild('scheduleObj')
    public scheduleObj?: ScheduleComponent;
    public allowResizing: Boolean = false;
    public allowDragDrop: Boolean = false;
    public selectedDate: Date = new Date(2024, 1, 15);
    public eventSettings: EventSettingsModel = { dataSource: <Object[]>extend([], scheduleData, undefined, true) };

    public gridData: Record<string, any>[] = [
        {
            OrderID: 10248, CustomerID: 'VINET', Role: 'Admin', EmployeeID: 5,
            ShipName: 'Vins et alcools Chevalier', ShipCity: 'Reims', ShipAddress: '59 rue de l Abbaye',
            ShipRegion: 'CJ', Mask: '1111', ShipPostalCode: '51100', ShipCountry: 'France', Freight: 32.38, Verified: !0,
            OrderDate: new Date('2024-01-01')
        },
        {
            OrderID: 10249, CustomerID: 'TOMSP', Role: 'Employee', EmployeeID: 6,
            ShipName: 'Toms Spezialitäten', ShipCity: 'Münster', ShipAddress: 'Luisenstr. 48',
            ShipRegion: 'CJ', Mask: '2222', ShipPostalCode: '44087', ShipCountry: 'Germany', Freight: 11.61, Verified: !1,
            OrderDate: new Date('2024-01-02')
        },
        {
            OrderID: 10250, CustomerID: 'HANAR', Role: 'Admin', EmployeeID: 4,
            ShipName: 'Hanari Carnes', ShipCity: 'Rio de Janeiro', ShipAddress: 'Rua do Paço, 67',
            ShipRegion: 'RJ', Mask: '3333', ShipPostalCode: '05454-876', ShipCountry: 'Brazil', Freight: 65.83, Verified: !0,
            OrderDate: new Date('2024-01-03')
        },
        {
            OrderID: 10251, CustomerID: 'VICTE', Role: 'Manager', EmployeeID: 3,
            ShipName: 'Victuailles en stock', ShipCity: 'Lyon', ShipAddress: '2, rue du Commerce',
            ShipRegion: 'CJ', Mask: '4444', ShipPostalCode: '69004', ShipCountry: 'France', Freight: 41.34, Verified: !0,
            OrderDate: new Date('2024-01-04')
        },
        {
            OrderID: 10252, CustomerID: 'SUPRD', Role: 'Manager', EmployeeID: 2,
            ShipName: 'Suprêmes délices', ShipCity: 'Charleroi', ShipAddress: 'Boulevard Tirou, 255',
            ShipRegion: 'CJ', Mask: '5555', ShipPostalCode: 'B-6000', ShipCountry: 'Belgium', Freight: 51.3, Verified: !0,
            OrderDate: new Date('2024-01-05')
        },
        {
            OrderID: 10253, CustomerID: 'HANAR', Role: 'Admin', EmployeeID: 7,
            ShipName: 'Hanari Carnes', ShipCity: 'Rio de Janeiro', ShipAddress: 'Rua do Paço, 67',
            ShipRegion: 'RJ', Mask: '6666', ShipPostalCode: '05454-876', ShipCountry: 'Brazil', Freight: 58.17, Verified: !0,
            OrderDate: new Date('2024-01-06')
        },
        {
            OrderID: 10254, CustomerID: 'CHOPS', Role: 'Employee', EmployeeID: 5,
            ShipName: 'Chop-suey Chinese', ShipCity: 'Bern', ShipAddress: 'Hauptstr. 31',
            ShipRegion: 'CJ', Mask: '7777', ShipPostalCode: '3012', ShipCountry: 'Switzerland', Freight: 22.98, Verified: !1,
            OrderDate: new Date('2024-01-07')
        }

    ]

    public onBeforePaste(args: BeforePasteEventArgs) {
        if (typeof args.data === 'string') {
            const dataArray: string[] = (args.data as string).split('\t');
            const result: ScheduleData = {
                Id: dataArray[0],
                Subject: dataArray[1],
                StartTime: new Date(dataArray[4]).toISOString(),
                EndTime: new Date(new Date(dataArray[4]).getTime() + 60 * 60 * 1000).toISOString(),
                Location: dataArray[2],
                Description: dataArray[3]
            };
            args.data = [result];
        }
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

You can refer to our Angular Scheduler feature tour page for its groundbreaking feature representations. You can also explore our Angular Scheduler example to knows how to present and manipulate data.