How to adjust the horizontal scrollbar automatically to display the current date at the initial position of the timeline month view?
The following steps shows the way to adjust the horizontal scroll value, to display the current date at the initial position of the timeline month view.
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 ActionComplete event of Schedule with appropriate handler, which gets triggered on every successful schedule action completion.
@(Html.EJ().Schedule("Schedule1") .Width("100%") .CellWidth("70px") .Height("525px") .CurrentDate(new DateTime(2016, 10, 25)) .Orientation(Orientation.Horizontal) .AppointmentSettings(fields => fields.Datasource(ViewBag.datasource) .Id("Id") .Subject("Subject") .StartTime("StartTime") .EndTime("EndTime") .Description("Description") .AllDay("AllDay") .Recurrence("Recurrence") .RecurrenceRule("RecurrenceRule")) .ScheduleClientSideEvents(evt => evt.ActionComplete("OnActionComplete")) ) |
Step 3: Here, OnActionComplete is an event handler function, within which the code to move the horizontal scrollbar to specific position has been added, so that the current date in the month view is positioned to display first. It is done by checking whether the current request type is ‘viewNavigate’ and also the current view is ‘month’ as shown in the below code example.
function OnActionComplete(args) { var scheduleObj = $("#Schedule1").data("ejSchedule"); var scrollerObj = scheduleObj.element.find('div#' + scheduleObj._id + '_scroller').data("ejScroller"); if ((!ej.isNullOrUndefined(scrollerObj)) && args.requestType == "viewNavigate" && args.data.currentView == "month") { scheduleObj.element.find("div#" + scheduleObj._id + "_scroller").ejScroller({ scrollLeft: (scheduleObj.cellwidth * (scheduleObj.currentDate().getDate() - 1)) }); } } |
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/sample-800205219
Step 4: Run the above sample and the horizontal scrollbar will be adjusted automatically to display the current date at the initial position as shown below.
Figure 1: Month view with adjusted horizontal scrollbar.