How to round off the minutes while drag and dropping the appointment?
The following steps helps you to round off the appointment dragging interval to specific time such as 15 minutes.
Step 1: Create an MVC application and include the EJMVC Schedule control in it by referring the following KB link,
https://syncfusion.com/kb/3606/how-to-add-the-ejmvc-schedule-control-in-the-mvc-application
Step 2: Define the DragStop event for Scheduler with appropriate handler. When the appointment is drag and dropped, this event will raise where we can round-off the appointment dragging minutes.
@(Html.EJ().Schedule("Schedule1") .Width("100%") .Height("100%") .TimeZone("UTC -03:00") .CurrentDate(new DateTime(2015, 11, 12)) .ScheduleClientSideEvents(evt => evt.DragStop("onDragStop")) // this event will raise when the appointment is drag and dropped .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Home/GetData").CrudURL("/Home/Batch").Adaptor("UrlAdaptor")) .Id("Id") .Subject("Subject") .StartTime("StartTime") .EndTime("EndTime") .StartTimeZone("StartTimeZone") .EndTimeZone("EndTimeZone") .Description("Description") .AllDay("AllDay") .Recurrence("Recurrence") .RecurrenceRule("RecurrenceRule")) )
Step 3: onDragStop is a function within which the code to round-off the drag and dropped appointment minutes is defined as shown in the below code example,
function onDragStop(args) { // this function will be called when the appointment is drag and dropped var start=args.appointment.StartTime; // start time of the appointment will be retrieved var starthr=15 * Math.round( start.getMinutes() / 15 ); // here we are rounding off the minutes if(starthr==60) { args.appointment.StartTime.setHours(args.appointment.StartTime.getHours()+1); // here we are incrementing the start hour when the minutes is equal to 60 } args.appointment.StartTime.setMinutes((Math.round(start.getMinutes()/15)*15 )% 60); // here we are adding the round off start minutes to the appointment var end=args.appointment.EndTime; var endhr=15 * Math.round( end.getMinutes() / 15 ); if(endhr==60) { args.appointment.EndTime.setHours(args.appointment.EndTime.getHours()+1); } args.appointment.EndTime.setMinutes((Math.round(end.getMinutes()/15)*15 )% 60); }
If you wish to round-off to other intervals, replace the value 15 with your appropriate minute value
Step 4: Run the sample and now you can see the time difference of 15 minutes as dragging interval as shown in the below images,
Figure 1: Appointment is drag and dropped to Nov 12, 2015 12.10 PM.
Figure 2: Appointment minutes rounded-off to the interval of 15 minutes.
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/155535/ze/Drag_and_drop1794655969
Conclusion
I hope you enjoyed learning about how to round off the minutes while drag and dropping the appointment.
You can refer to our ASP.NET MVC Schedule feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC Schedule example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!