We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

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: http://mvc.syncfusion.com/demos/web/schedule/default

Grid: http://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,

 

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

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

MVC Sample: http://www.syncfusion.com/downloads/support/directtrac/156882/ze/MVC-Sample616743427

ASP Sample: http://www.syncfusion.com/downloads/support/directtrac/156882/ze/ASP-Sample1167117298

JS Sample: http://jsplayground.syncfusion.com/p4nlepqa

Article ID: Published Date: Last Revised Date: Platform: Control:
7679 04/25/2017 04/25/2017 ASP.NET MVC Schedule
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon