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

[Solved] Next/Previous Appointment

2 Answers 234 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Adam Nelson
Top achievements
Rank 2
Adam Nelson asked on 13 Mar 2008, 10:08 PM
Is there a way (client side or server) for the scheduler to find the next or previous appointment and change the selected date to that appointment for easy navigation.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Milushev
Telerik team
answered on 17 Mar 2008, 02:21 PM
Hi Adam Nelson,

There is no integrated way to do this with RadScheduler, but you can easily add two buttons to your page that navigate from the current date to the next/previous appointment.

The only tricky part is sorting the Appointments, because you need a custom comparer. Here is the code to implement one:

class AppointmentComparer : IComparer 
    public int Compare(object x, object y) 
    { 
        Appointment first = x as Appointment; 
        Appointment second = y as Appointment; 
 
        if (first == null || second == null
        { 
            throw new InvalidOperationException("Can't compare null object(s)."); 
        } 
 
        if (first.Start < second.Start) 
        { 
            return -1; 
        } 
 
        if (first.Start > second.Start) 
        { 
            return 1; 
        } 
 
        if (first.End > second.End) 
        { 
            return -1; 
        } 
 
        return 0; 
    } 

After you have the AppointmentComparer, in the button's click handler you just need to sort the appointments and find the nearest next Appointment:

protected void Button1_Click(object sender, EventArgs e) 
    Appointment[] appointments = RadScheduler1.Appointments.ToArray(); 
    Array.Sort(appointments, new AppointmentComparer()); 
 
    foreach (Appointment appointment in appointments) 
    { 
        DateTime appointmentStart = RadScheduler1.UtcToDisplay(appointment.Start); 
        if (appointmentStart > RadScheduler1.SelectedDate) 
        { 
            RadScheduler1.SelectedDate = appointmentStart.Date; 
            break
        } 
    } 

For the "Previous" button, just switch the 'if' to check if appointmentStart is before SelectedDate:

    if (appointmentStart < RadScheduler1.SelectedDate)

Greetings,
Dimitar Milushev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Adam Nelson
Top achievements
Rank 2
answered on 21 Mar 2008, 08:23 PM
Thank you very much for the feedback.

It worked for the most part.

I had to add

Array.Reverse(appointments)

after the sort for the "Previous" button otherwise it would always set the selected date to the very first appointment.
Tags
Scheduler
Asked by
Adam Nelson
Top achievements
Rank 2
Answers by
Dimitar Milushev
Telerik team
Adam Nelson
Top achievements
Rank 2
Share this question
or