Articles in this section
Category / Section

How to set the scroll position of Scheduler based on the current time?

3 mins read

The initial scheduler view can be set to display its work area based on the current time indication or any other specific user-defined time. If the user wish to auto-scroll the initial screen based on the current system time, follow the below steps,

Step 1:  Create a schedule default sample with JSON data. Also, add and refer the required scripts and stylesheets to it by referring the following link.

Sample Location: http://jsplayground.syncfusion.com/ufe2cbm0

Step 2:  Define the create and actionComplete event for Scheduler with appropriate handler. These two events were used specifically because - when any of the scheduler action (like appointment creation, view/date navigation) completes and also during the initial rendering of the scheduler, the scroller within the scheduler will be positioned every time based on the current time indicator.

JavaScript

 
$(function () {
            var dManager = ej.DataManager(window.Default).executeLocal(ej.Query().take(10));
            $("#Schedule1").ejSchedule({
              width: "100%",
              height: "525px",
        currentDate:new Date(),
              currentView:"Day",
              create:"currentTime",
              actionComplete:"currentTime",
              appointmentSettings: {
                    dataSource: dManager,
                    id: "Id",
                    subject: "Subject",
                    startTime: "StartTime",
                    endTime: "EndTime",
        description:"Description",
                    allDay: "AllDay",
                    recurrence: "Recurrence",
                    recurrenceRule: "RecurrenceRule"
                }                      
            });
        });
 
 

 

Step 3:  currentTime is a function within which the code to handle the exact scroller position based on current time Indicator is defined. The following code example shows the logic to position the scroller,

 
  function currentTime()
          {
              var scheobj = $("#Schedule1").data("ejSchedule");
              if (scheobj.element.find('.e-highlightcurrenttimeline').length>0) {
                  var rowindex = ($('.e-highlightcurrenttimeline')[0].offsetTop / scheobj.element.find('.e-workcells').height()) - 1;
                  var highScrol = scheobj.element.find('.e-highlightcurrenttimeline').length != 0 ? rowindex * scheobj.element.find('.e-workcells').height() : 0;
                  $('div#' + scheobj._id + "_scroller").ejScroller({ scrollTop: highScrol });
                  scheobj.element.find('.e-scrolltimecells').css('top', -(scheobj.element.find('.e-draggableworkarea').scrollTop()) + 'px');
              }
          }
 

 

Step 4: Run the sample and now you can view the Scheduler view showing off from the time 9.00 AM, as the current time of the system points to that time. The user can also view the current time indicator position on the Scheduler as depicted in the below image,Scheduler area scrolled to the position based on current time indicator

 Figure 1: Scheduler area scrolled to the position based on current time indicator.

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