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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: JavaScript |
Control: ejSchedule |
Published Date: March 1, 2016 |
Last Revised Date: May 28, 2019

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.

ADD COMMENT
You must log in to leave a comment
Comments
Vivek Sharma
Jan 25, 2017
How can we achieve the same if our schedule is set horizontol? Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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