Scroll to current day

4 posts, 0 answers
  1. Justin
    Justin avatar
    3 posts
    Member since:
    Jul 2014

    Posted 05 Jan Link to this post

    I've seen this snippet of code on the forums which supposedly moves the gantt view to the current date:

     this.RadGantt1.ScrollingService.ScrollToDateTime(DateTime.Today);

    Unfortunately it seems to be deprecated and I can't find a suitable option in the help (or in the control methods).

    Any help would be appreciated.

     

    thanks.

  2. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 07 Jan Link to this post

    Hello,

    Could you please clarify whether you are using the Gantt control for ASP.NET Ajax or Silverlight, since the ASP.NET version doesn't have a ScrollingService implementation?

    Regards,
    Bozhidar
    Telerik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Justin
    Justin avatar
    3 posts
    Member since:
    Jul 2014

    Posted 07 Jan Link to this post

    Apologies, I'm using the ASP.Net version.All I want to do is select the current date on page load (similar to a date picker etc).

     Thanks.

  5. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 11 Jan Link to this post

    Hi,

    Thank you for clarifying.

    You can use the following javascript to scroll to the current date:
    function pageLoad() {
        $find("RadGantt1")._widget.bind("dataBound", ganttDataBound);
    }
     
    function ganttDataBound() {
        var view = $find("RadGantt1")._widget.timeline.view();
        var viewStart = view.start;
        var viewEnd = view.end;
        var currentDate = new Date();
     
        if (currentDate > viewStart && currentDate < viewEnd) {
            var offset = view._offset(currentDate);
     
            // decrease the offset by some amount, so that
            // the current day indicator is not right next
            // to the splitter
            offset -= 100;
     
            view.content.scrollLeft(offset);
        }
    }

    One thing to keep in mind is that the gantt may not always show the current date. The range shown in the timeline is determined by the loaded tasks, and if the tasks are all before or after the current date, it won't be visible. This behavior is by design and cannot be changed.

    Regards,
    Bozhidar
    Telerik
Back to Top