Articles in this section
Category / Section

How to drag and drop records from Grid to the Schedule control ?

2 mins read

How to drag and drop records from Grid to the Schedule control and vice versa?

 

The following steps helps you to drag and drop records from Grid to the Schedule control and vice versa

Step 1:  Create an MVC application and include the default Schedule and Grid control in it by referring the following links,

Schedule: https://mvc.syncfusion.com/demos/web/schedule/default

Grid: https://mvc.syncfusion.com/demos/web/grid/default

Step 2: Define the DragStop event for Scheduler and RowDrop event for Grid with appropriate handler. 

@(Html.EJ().Schedule("Schedule1")

        .Width("100%")

        .Height("525px")

        .AppointmentDragArea("body")

        .CurrentDate(new DateTime(2015, 9, 12))

        .ScheduleClientSideEvents(evt =>

             evt.DragStop("onDragStop"))

            .AppointmentSettings(fields => fields

            .ApplyTimeOffset(false)

            .Id("Id")

            .Subject("Subject")

            .StartTime("StartTime")

            .EndTime("EndTime")

            .AllDay("AllDay")

            .Recurrence("Recurrence")

            .RecurrenceRule("RecurrenceRule"))

)

 

@(Html.EJ().Grid<object>("OrdersGrid")

            .Datasource((IEnumerable<object>)ViewBag.datasource1)

            .AllowRowDragAndDrop()

            .RowDropSettings(drop => drop.DropTargetID("#Schedule1"))

            .ClientSideEvents(eve => eve.RowDrop("rowDropHandler"))

                .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

)

 

 

Step 3: onDragStop and rowDropHandler is a function within which the code to drag and drop appointment/record from Schedule and Grid are defined as shown in the below code example,

    function rowDropHandler(args) { // this event function will be called when the record is drag and dropped from Grid

        var object = $("#Schedule1").data("ejSchedule"); // here object for Schedule is created

        object.saveAppointment(args.data[0]); // here we are passing the record to the public save function to render in Schedule

        var gridObject = $("#OrdersGrid").data("ejGrid"); // here object for Grid is created

        gridObject.deleteRecord("Id", args.data[0]); // here we are deleting the drag and dropped appointment from Grid

    }

 

function onDragStop(args) {// drag and drop an appointment to other control 

        if (args.event != undefined) {

            var scheobj = $("#Schedule1").data("ejSchedule");

            if ($(args.event.target).hasClass('e-rowcell')) {

                $("#OrdersGrid").ejGrid("addRecord", { Id: args.appointment.Id, Subject: args.appointment.Subject, AllDay: args.appointment.AllDay, EndTime: args.appointment.EndTime, StartTime: args.appointment.StartTime, Recurrence: args.appointment.Recurrence, RecurrenceRule: args.appointment.RecurrenceRule });

                scheobj.deleteAppointment(args.appointment.Guid);

                ($(document.body).find(".e-scheduleAppGlassy").length > 0) && $(document.body).find(".e-scheduleAppGlassy").remove();

            }

        }

    }

 

Step 4: Run the sample and now you can drag and drop the appointments from Schedule to Grid and vice versa as shown in the below images,

 

Record is drag and dropped to Schedule from Grid

Figure 1: Record is drag and dropped to Schedule from Grid.

Appointment is drag and dropped to Grid from Schedule

Figure 2: Appointment is drag and dropped to Grid from Schedule.

MVC Sample: https://www.syncfusion.com/downloads/support/directtrac/156882/ze/Schedulewith_grid-1953899562.zip

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied