- Cut, copy and paste using keyboard
- Cut, copy, and paste using context menu
- Modifying content before pasting
Contact Support
Clipboard in ASP.NET CORE Schedule component
20 Dec 202421 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
@using Syncfusion.EJ2.Schedule
<ejs-schedule id="schedule" height="650px" selectedDate="new DateTime(2024, 2, 15)" allowDragAndDrop="false"
allowResizing="false" allowClipboard="true" showQuickInfo="false">
<e-schedule-eventsettings dataSource="@ViewBag.appointments"></e-schedule-eventsettings>
</ejs-schedule>
public ActionResult Index()
{
ViewBag.appointments = GetScheduleData();
return View();
}
public List<AppointmentData> GetScheduleData()
{
List<AppointmentData> appData = new List<AppointmentData>();
appData.Add(new AppointmentData
{
Id = 2,
Subject = "Meeting",
StartTime = new DateTime(2024, 2, 15, 10, 0, 0),
EndTime = new DateTime(2024, 2, 15, 12, 30, 0),
IsAllDay = false,
Status = "Completed",
Priority = "High"
});
return appData;
}
public class AppointmentData
{
public int Id { get; set; }
public string Subject { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public bool IsAllDay { get; set; }
public string Status { get; set; }
public string Priority { get; set; }
}
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.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule
@using Syncfusion.EJ2.Navigations
<ejs-schedule id="schedule" height="650px" selectedDate="new DateTime(2024, 2, 15)" allowDragAndDrop="false" allowResizing="false" allowClipboard="true" showQuickInfo="false">
<e-schedule-eventsettings dataSource="@ViewBag.appointments"></e-schedule-eventsettings>
</ejs-schedule>
<ejs-contextmenu id="ScheduleContextMenu" target=".e-schedule" items="@ViewBag.menuItems" beforeOpen="onContextMenuBeforeOpen" select="onMenuItemSelect" cssClass="schedule-context-menu"></ejs-contextmenu>
<style>
.schedule-context-menu .e-menu-item .new::before {
content: '\e7f9';
}
.schedule-context-menu .e-menu-item .edit::before {
content: '\ea9a';
}
.schedule-context-menu .e-menu-item .recurrence::before {
content: '\e308';
font-weight: bold;
}
.schedule-context-menu .e-menu-item .today::before {
content: '\e322';
}
.schedule-context-menu .e-menu-item .delete::before {
content: '\e94a';
}
.e-bigger .schedule-context-menu ul .e-menu-item .e-menu-icon {
font-size: 14px;
}
.schedule-context-menu ul .e-menu-item .e-menu-icon {
font-size: 12px;
}
</style>
<script type="text/javascript">
var selectedTarget;
var targetElement;
function onContextMenuBeforeOpen(args) {
var newEventElement = document.querySelector('.e-new-event');
if (newEventElement) {
ej.base.remove(newEventElement);
}
var scheduleObj = document.getElementById('schedule').ej2_instances[0];
scheduleObj.closeQuickInfoPopup();
targetElement = args.event.target;
if (ej.base.closest(targetElement, '.e-contextmenu')) {
return;
}
selectedTarget = ej.base.closest(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 (ej.base.isNullOrUndefined(selectedTarget)) {
args.cancel = true;
return;
}
if (selectedTarget.classList.contains('e-appointment')) {
this.showItems(['Cut', 'Copy'], true);
this.hideItems(['Paste'], true);
} else {
this.showItems(['Paste'], true);
this.hideItems(['Cut', 'Copy'], true);
}
}
function onMenuItemSelect(args) {
var scheduleObj = document.getElementById('schedule').ej2_instances[0];
var selectedMenuItem = args.item.id;
switch (selectedMenuItem) {
case 'Cut':
scheduleObj.cut([selectedTarget]);
break;
case 'Copy':
scheduleObj.copy([selectedTarget]);
break;
case 'Paste':
scheduleObj.paste(targetElement);
break;
}
}
</script>
public ActionResult Index()
{
ViewBag.appointments = GetScheduleData();
List<object> menuItems = new List<object>();
menuItems.Add(new
{
text = "Cut Event",
iconCss = "e-icons e-cut",
id = "Cut"
});
menuItems.Add(new
{
text = "Copy Event",
iconCss = "e-icons e-copy",
id = "Copy"
});
menuItems.Add(new
{
text = "Paste",
iconCss = "e-icons e-paste",
id = "Paste"
});
ViewBag.menuItems = menuItems;
return View();
}
public List<AppointmentData> GetScheduleData()
{
List<AppointmentData> appData = new List<AppointmentData>();
appData.Add(new AppointmentData
{
Id = 2,
Subject = "Meeting",
StartTime = new DateTime(2024, 2, 15, 10, 0, 0),
EndTime = new DateTime(2024, 2, 15, 12, 30, 0),
IsAllDay = false,
Status = "Completed",
Priority = "High"
});
return appData;
}
public class AppointmentData
{
public int Id { get; set; }
public string Subject { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public bool IsAllDay { get; set; }
public string Status { get; set; }
public string Priority { get; set; }
}
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:
- Select an Item: Click on an item in the grid.
- Copy the Details: Press Ctrl + C to copy the selected event details.
- Choose a Time Slot: Click on the desired time slot in the scheduler.
- 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.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule
<div class="schedule-container">
<ejs-schedule id="schedule" height="650px" selectedDate="new DateTime(2024, 2, 15)" allowDragAndDrop="false"
allowResizing="false" allowClipboard="true" showQuickInfo="false" beforePaste="onBeforePaste">
<e-schedule-eventsettings dataSource="@ViewBag.appointments"></e-schedule-eventsettings>
</ejs-schedule>
<ejs-grid id="Grid" width="40%" height="400px" dataSource="@ViewBag.gridData" cssClass="drag-grid"
allowSelection="true">
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="90"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="100"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="100"></e-grid-column>
<e-grid-column field="ShipName" headerText="Ship Name" width="130"></e-grid-column>
<e-grid-column field="OrderDate" headerText="Order Date" format="yMd" textAlign="Right" width="100"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<style>
.schedule-container {
display: flex;
justify-content: space-between;
}
@@media screen and (max-width: 540px) {
.schedule-container {
flex-direction: column;
}
.e-grid {
width: 100% !important;
}
}
</style>
<script type="text/javascript">
function onBeforePaste(args) {
if (typeof args.data === 'string') {
var dataArray = (args.data).split('\t');
var result = {
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];
}
}
</script>
public ActionResult Index()
{
ViewBag.appointments = GetScheduleData();
var gridData = new List<Order>
{
new Order { OrderID = 10248, CustomerID = "VINET", ShipCity = "Reims", ShipName = "Vins et alcools Chevalier", OrderDate = new DateTime(2024, 1, 1) },
new Order { OrderID = 10249, CustomerID = "TOMSP", ShipCity = "Münster", ShipName = "Toms Spezialitäten", OrderDate = new DateTime(2024, 1, 2) },
new Order { OrderID = 10250, CustomerID = "HANAR", ShipCity = "Rio de Janeiro", ShipName = "Hanari Carnes", OrderDate = new DateTime(2024, 1, 3) },
new Order { OrderID = 10251, CustomerID = "VICTE", ShipCity = "Lyon", ShipName = "Victuailles en stock", OrderDate = new DateTime(2024, 1, 4) },
new Order { OrderID = 10252, CustomerID = "SUPRD", ShipCity = "Charleroi", ShipName = "Suprêmes délices", OrderDate = new DateTime(2024, 1, 5) },
new Order { OrderID = 10253, CustomerID = "HANAR", ShipCity = "Rio de Janeiro", ShipName = "Hanari Carnes", OrderDate = new DateTime(2024, 1, 6) },
new Order { OrderID = 10254, CustomerID = "CHOPS", ShipCity = "Bern", ShipName = "Chop-suey Chinese", OrderDate = new DateTime(2024, 1, 7) }
};
ViewBag.gridData = gridData;
return View();
}
public List<AppointmentData> GetScheduleData()
{
List<AppointmentData> appData = new List<AppointmentData>();
appData.Add(new AppointmentData
{
Id = 2,
Subject = "Meeting",
StartTime = new DateTime(2024, 2, 15, 10, 0, 0),
EndTime = new DateTime(2024, 2, 15, 12, 30, 0),
IsAllDay = false,
Status = "Completed",
Priority = "High"
});
return appData;
}
public class AppointmentData
{
public int Id { get; set; }
public string Subject { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public bool IsAllDay { get; set; }
public string Status { get; set; }
public string Priority { get; set; }
}
public class Order
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public string ShipCity { get; set; }
public string ShipName { get; set; }
public DateTime OrderDate { get; set; }
}
You can refer to our ASP.NET Core Scheduler feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET Core Scheduler example to knows how to present and manipulate data.