Timeline View - Set First Date

3 posts, 1 answers
  1. Kieron
    Kieron avatar
    16 posts
    Member since:
    Nov 2013

    Posted 03 Jun Link to this post

    Hi,

    Is it possible to use the timeline layout for 7 days but setting the first date shown to be the first day of the week.  If I switch from Day view to Timeline view, the first day shown in the Timeline is always the day you were looking at in Day View whereas I would like it to be the first day of that week - Monday.

    I would use Week View but when I put it into Horizontal orientation to try and emulate the Timeline layout, the date part of the TimeRuler sits on the Y axis (along with each Resource) and this stretches out each Resource bigger than I would like - ideally I want the dates to stay with the times on the TimeRuler.

     

    Thanks.

     

  2. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 06 Jun Link to this post

    Hi Kieron,

    Indeed, TimelineViewDefinition starts from the CurrentDate while WeekViewDefinition starts from the first day of the week containing CurrentDate.  You could check How to configure the VisibleRange topic for more details on the different ViewDefinitions.

    You could achieve the required approach by subscribing to VisibleRangeChanged event of the ScheduleView and update the CurrentDate in its handler. Here is a quick example:

    <telerik:RadScheduleView x:Name="radScheduleView"
                AppointmentsSource="{Binding Appointments}" FirstDayOfWeek="Sunday"
                VisibleRangeChanged="radScheduleView_VisibleRangeChanged">
        <telerik:RadScheduleView.ViewDefinitions>
            <telerik:WeekViewDefinition/>
            <telerik:TimelineViewDefinition  />                     
        </telerik:RadScheduleView.ViewDefinitions>
    </telerik:RadScheduleView>

    private void radScheduleView_VisibleRangeChanged(object sender, EventArgs e)
    {
        var scheduleView = sender as RadScheduleView;
        if (scheduleView.ActiveViewDefinition is TimelineViewDefinition)
        {
            scheduleView.CurrentDate = GetFirstDateOfWeek(scheduleView.CurrentDate, DayOfWeek.Sunday);
        }
    }
     
    public  DateTime GetFirstDateOfWeek(DateTime dayInWeek, DayOfWeek firstDay)
    {
        DateTime firstDayInWeek = dayInWeek.Date;
        while (firstDayInWeek.DayOfWeek != firstDay)
            firstDayInWeek = firstDayInWeek.AddDays(-1);
        return firstDayInWeek;
    }

    I hope this would be helpful.

    Regards,
    Yana
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kieron
    Kieron avatar
    16 posts
    Member since:
    Nov 2013

    Posted 07 Jun in reply to Yana Link to this post

    Thanks, it solves the problem
Back to Top