This is a migrated thread and some comments may be shown as answers.

Scroll to current day

3 Answers 96 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 05 Jan 2016, 08:46 AM

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.

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 07 Jan 2016, 07:20 AM
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
0
Justin
Top achievements
Rank 1
answered on 07 Jan 2016, 08:39 AM

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.

0
Bozhidar
Telerik team
answered on 11 Jan 2016, 09:18 AM
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
Tags
Gantt
Asked by
Justin
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Justin
Top achievements
Rank 1
Share this question
or