Articles in this section
Category / Section

How to load appointments on demand in the SfSchedule ?

4 mins read

You can load the appointment on demand by using the VisibleDatesChanging event in the SfSchedule control.

Loading the appointment on demand in Schedule.

  1. Create a WinRT application and add Schedule control to it.

XAML

<syncfusion:SfSchedule  ScheduleType="Month" x:Name="schedule"  >
 </syncfusion:SfSchedule>
  1. Create the appointment collection that needs to be loaded to the Schedule control based on the condition. The following code example creates the appointment collection.

C#

ScheduleAppointmentCollection AppColl;
        public MainPage()
        {
            this.InitializeComponent();
            AppColl = new ScheduleAppointmentCollection
            {
               new ScheduleAppointment { Subject = "Meeting", StartTime = date.AddHours(0), EndTime = date.AddHours(2) },
               new ScheduleAppointment { Subject = "Conference", StartTime = date.SubractDays(30).AddHours(0), EndTime = date.SubractDays(30).AddHours(2)},
               new ScheduleAppointment { Subject = "Travelling", StartTime = date.AddDays(3).AddHours(0), EndTime = date.AddDays(3).AddHours(2) },
               new ScheduleAppointment { Subject = "Treatment", StartTime = date.AddDays(5).AddHours(0), EndTime = date.AddDays(5).AddHours(2) },
               new ScheduleAppointment { Subject = "School", StartTime = date.AddHours(5), EndTime = date.AddHours(7) },
               new ScheduleAppointment { Subject = "Meeting", StartTime = date.SubractDays(35).AddHours(0), EndTime = date.SubractDays(35).AddHours(2)},
               new ScheduleAppointment { Subject = "Birthday", StartTime = date.AddDays(29).AddHours(0), EndTime = date.AddDays(3).AddHours(2) },
               new ScheduleAppointment { Subject = "Treatment", StartTime = date.AddDays(20).AddHours(0), EndTime = date.AddDays(5).AddHours(2) },
                     };
             schedule.VisibleDatesChanging += schedule_VisibleDatesChanging;
        }
  1. Now, trigger the VisibleDatesChanging event in the Schedule control. Create a new appointment collection to store the filtered appointment from the original appointment collection. In the VisibleDatesChanging event, e.NewValue parameter is used to store the current visible dates of the Schedule control. By using the visible dates collection in the e.NewValue parameter, you can load appointment on demand as given in the following code example.

C#

void schedule_VisibleDatesChanging(object sender, VisibleDatesChangingEventArgs e)
        {
            ScheduleAppointmentCollection FilteredAppColl=new ScheduleAppointmentCollection();
         var dateCollection = e.NewValue as ObservableCollection<DateTime>;
                      foreach(ScheduleAppointment App in AppColl)
            {
                if (dateCollection.First() <= App.StartTime && App.EndTime<=dateCollection.Last() )
                {
                    FilteredAppColl.Add(App);
                                    }
                           }
            schedule.Appointments = FilteredAppColl;
        }
  1. The appointments are stored in a filtered appointment collection, FilteredAppColl, that has StartTime and EndTime within the visible date’s collection. Then, the filtered appointments are loaded to the Schedule.
  2. On changing the visible dates in the Schedule, the appointments are loaded to the Schedule only when the StartTime and EndTime of appointments are within the visible dates collection.

The following screenshot displays the appointments on Schedule that have StartTime and EndTime within the visible date’s collection.

Schedule appointment loaded on demand

Figure 1: Schedule appointment loaded on demand

Sample Link:

Schedule_Data_Load_On_Demand

 

 

 

 

 

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