New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Drag and Drop from RadGrid to RadScheduler

This online demo demonstrates how to implement support for drag and drop from RadGrid to RadScheduler.

When a task is dragged from the grid to the scheduler, the time slot which will receive the appointment is highlighted. After the task is dropped, it appears in the RadScheduler control as an appointment and it is removed from the grid. This is achieved by updating the data sources and rebinding both controls.

Clicking the Unschedule button (implemented via AppointmentTemplate) removes the appointment and sends it back to the task list of the grid. In contrast, deleting an appointment removes the appointemnt altogether - both from the scheduler and the grid.

The appointments can be modified in the grid on row double-click, or new ones can be added using the Add new task button.

Drag and drop from grid to scheduler

Here follows the code used to achieve this:

JavaScript
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
   <script type="text/javascript">

       function rowDropping(sender, eventArgs) {
           // Fired when the user drops a grid row
           var htmlElement = eventArgs.get_destinationHtmlElement();
           var scheduler = $find('<%= RadScheduler1.ClientID %>');

           if (isPartOfSchedulerAppointmentArea(htmlElement)) {
               // The row was dropped over the scheduler appointment area
               // Find the exact time slot and save its unique index in the hidden field
               var timeSlot = scheduler._activeModel.getTimeSlotFromDomElement(htmlElement);

               $get("TargetSlotHiddenField").value = timeSlot.get_index();

               // The HTML needs to be set in order for the postback to execute normally
               eventArgs.set_destinationHtmlElement("TargetSlotHiddenField");
           }
           else {
               // The node was dropped elsewhere on the document
               eventArgs.set_cancel(true);
           }
       }

       function isPartOfSchedulerAppointmentArea(htmlElement) {
           // Determines if an html element is part of the scheduler appointment area
           // This can be either the rsContent or the rsAllDay div (in day and week view)
           return $telerik.$(htmlElement).parents().is("div.rsAllDay") ||
                       $telerik.$(htmlElement).parents().is("div.rsContent")
       }

       function onRowDoubleClick(sender, args) {
           sender.get_masterTableView().editItem(args.get_itemIndexHierarchical());
       }
   </script>
</telerik:RadScriptBlock>

The bind expressions in the markup use C# syntax. In order to view their VB translation please visit the above linked demo.

Not finding the help you need?
Contact Support