Articles in this section
Category / Section

How to adjust the scrollbar based on current time ?

2 mins read

This knowledge base article explains how to set the scroller position of scheduler based on the current system time.

 

Step 1: Create a default ASP.NET Web Forms Schedule sample by referring the below online link.

https://www.syncfusion.com/kb/3948/how-to-add-the-ejweb-schedule-control-in-the-asp-net-application

Step 2: Define the Scheduler Create and ActionComplete events which will be triggered during the initial load and on view navigation as shown below. 

<ej:Schedule ClientIDMode="Static" runat="server"
                ID="Schedule1" Orientation="Horizontal" Locale="en-US" Width="100%" DataSourceID="objectDataSource1" Height="525px" CurrentDate="10/12/2018"
                Views="Day,Week,WorkWeek,Month" StartHour="0" EndHour="24" CurrentView="Day" 
                AppointmentTemplateId="#MyTemplate" Create="onCreate" ActionComplete="onComplete">
                <Group Resources="Owners" />
                <Resources>
                    <ej:Resources Field="Owner" Name="Owners" Title="Owner" AllowMultiple="true">
                        <ResourceSettings Color="color" Id="id" Text="text">
                        </ResourceSettings>
                    </ej:Resources>
                </Resources>
                <ContextMenuSettings Enable="true">
                </ContextMenuSettings>
                <CategorizeSettings Enable="true">
                </CategorizeSettings>
                <PrioritySettings Enable="true"></PrioritySettings>
                <AppointmentSettings Id="ID" Subject="Subject" AllDay="AllDay" StartTime="StartTime" EndTime="EndTime" Description="Description" Recurrence="Recurrence" RecurrenceRule="RecurrenceRule" ResourceFields="Owner" />
            </ej:Schedule>

 

Step 3: By default, schedule scroller will be rendered based on work hour range (9 AM) as shown below.

Schedule control with scroll position on default work hour range

Figure 1: Schedule control with scroll position on default work hour range.

 

Step 4: To change its default position based on the current system time, scroller left value (for horizontal mode) / scroller top value (for vertical mode) needs to be updated with the current time cell range. The code to change the scroll position during the initial load and on view navigation is defined within the onCreate and onComplete functions as shown below.

function onCreate() {
    var scheduleObj = $("#Schedule1").data("ejSchedule");
    var scrollerObj = scheduleObj.element.find('div#' + scheduleObj._id + '_scroller').data("ejScroller");
    if ($(".e-highlightcurrenttimeline").length != 0 && (!ej.isNullOrUndefined(scrollerObj))) {
        if (scheduleObj.model.orientation == "horizontal")
            scheduleObj.element.find("div#" + scheduleObj._id + "_scroller").ejScroller({ scrollLeft: (parseInt($(".e-highlightcurrenttimeline").css("left")) - 100) });
        else
            scheduleObj.element.find("div#" + scheduleObj._id + "_scroller").ejScroller({ scrollTop: (parseInt($(".e-highlightcurrenttimeline").css("top")) - 100) });
    }
}
function onComplete(args) {
    if (args.requestType == "dateNavigate" || args.requestType == "viewNavigate")
        onCreate();
}

 

Step 5: Run the sample and the Schedule scroller will be displayed based on current time range (7 PM) as follows.

Schedule control display with new scroll position based on current time

Figure 2: Schedule control display with new scroll position based on current time.

 

Sample Link:

https://www.syncfusion.com/downloads/support/forum/133661/ze/Schedule_Scrollbar1051256954

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