What's the best way to sort SfSchedule Month Agenda View

I just want to know if anyone has found a good way to sort the Agenda View appointments in the Month View.  Do I have to sort my entire observable collection, or is there a better way?  I hate to have to keep resorting the collection for only the agenda view.

Any help will be greatly appreciated.


1 Reply

VR Vigneshkumar Ramasamy Syncfusion Team October 8, 2018 10:04 AM UTC

Hi John,  
  
Thanks for using Syncfusion products,  
  
Currently, Schedule doesn’t have support to sort the appointment’s in Agenda view. But, you can achieve this by adding custom agenda view, we have prepared a simple sample for the same in the sample we have added schedule in a grid with schedule occupies 70% of screen and listview occupies the remaining 30% screen.  
<Grid x:Name="GridView">  
        <Grid.Resources>  
            <ResourceDictionary>  
                <local:ItemsCountConverter x:Key ="countConverter" />  
            </ResourceDictionary>  
        </Grid.Resources>  
          
        <Grid.BindingContext>  
            <local:AgendaViewModel/>  
        </Grid.BindingContext>  
        <Grid.RowDefinitions>  
            <RowDefinition Height="0.7*"/>  
            <RowDefinition Height="0.3*"/>  
        </Grid.RowDefinitions>  
  
        <schedule:SfSchedule x:Name="schedule" Grid.Row="0"  
                             BindingContext="{Binding}"  
                             ScheduleView="MonthView"  
                             SelectedDate="{Binding SelectedDate, Mode=TwoWay}"  
                             DataSource="{Binding Meetings}">  
            <schedule:SfSchedule.ShowAppointmentsInline>  
                <OnPlatform x:TypeArguments="x:Boolean">  
                    <On Platform="Android,iOS">False</On>  
                    <On Platform="UWP">True</On>  
                </OnPlatform>  
            </schedule:SfSchedule.ShowAppointmentsInline>  
            <schedule:SfSchedule.AppointmentMapping>  
                <schedule:ScheduleAppointmentMapping  
                    StartTimeMapping="From"  
                    EndTimeMapping="To"  
                    SubjectMapping="EventName"  
                    ColorMapping="color">  
                </schedule:ScheduleAppointmentMapping>  
            </schedule:SfSchedule.AppointmentMapping>  
        </schedule:SfSchedule>  
        <Grid x:Name="ListView" Grid.Row="1">  
            <Grid.RowDefinitions>  
                <RowDefinition Height="0.2*"/>  
                <RowDefinition Height="*"/>  
            </Grid.RowDefinitions>  
  
            <Label Grid.Row="0"  
                   x:Name="SelectedDate"  
                   HorizontalOptions="Start"  
                   Text="{Binding SelectedDate}"  
                   TextColor="Black"  
                   FontAttributes="Bold"    
                   FontSize="14"  
                   VerticalOptions="Start" />  
            <Grid Grid.Row="1">  
                <listview:SfListView ItemsSource="{Binding OrderedMeetings}">  
                    <listview:SfListView.ItemTemplate>  
                        <DataTemplate>  
                            <ViewCell>  
                                <Grid Margin="2,1,1,1">  
                                    <Grid.ColumnDefinitions>  
                                        <ColumnDefinition Width="0.02*"/>  
                                        <ColumnDefinition Width="0.78*"/>  
                                        <ColumnDefinition Width="0.2*"/>  
                                    </Grid.ColumnDefinitions>  
                                    <Grid  
                        BackgroundColor="{Binding color}"  
                        Grid.Column="0" >  
                                    </Grid>  
                                    <Label  
                        Text="{Binding EventName}"  
                        Grid.Column="1"  
                        VerticalOptions="Center"  
                        LineBreakMode="TailTruncation"  
                        TextColor="Black" >  
                                    </Label>  
                                    <Grid  
                       Margin="2"  
                       Grid.Column="2">  
                                        <Grid.RowDefinitions>  
                                            <RowDefinition />  
                                            <RowDefinition />  
                                        </Grid.RowDefinitions>  
                                        <Label  
                          Text="{Binding From, StringFormat='{}{0:hh:mm tt}'}}"  
                          Grid.Row="0"  
                          VerticalOptions="Center"  
                          FontSize="10"  
                          TextColor="Gray" >  
                                        </Label>  
                                        <Label  
                          Text="{Binding To, StringFormat='{}{0:hh:mm tt}'}}"  
                          Grid.Row="1"  
                          VerticalOptions="Center"  
                          FontSize="10"  
                          TextColor="Gray">  
                                        </Label>  
                                    </Grid>  
                                </Grid>  
                            </ViewCell>  
                        </DataTemplate>  
                    </listview:SfListView.ItemTemplate>  
                </listview:SfListView>  
                <Label  
              Margin="5,0,0,0"  
              BindingContext="{Binding}"  
              Text="No Meetings"  
              IsVisible="{Binding SelectedDateMeetings, Converter={StaticResourcecountConverter}}" />  
            </Grid>  
        </Grid>  
    </Grid>  
    <ContentPage.Behaviors>  
        <local:AgendaViewBehavior/>  
    </ContentPage.Behaviors>  
  
We have got the selected date meetings from schedule’s celltappedevent and order the events based on start time and bind this to ItemSource property of list view, please find the code snippet below.  
private void ScheduleCellTapped(object sender, CellTappedEventArgs e)  
        {  
            var viewModel = (this.schedule.BindingContext as AgendaViewModel);  
            if (e.Appointments != null)  
            {  
                viewModel.SelectedDateMeetings = new ObservableCollection<Meeting>();  
                foreach (var item in e.Appointments)  
                {  
                    viewModel.SelectedDateMeetings.Add(item as Meeting);  
                    viewModel.OrderedMeetings = viewModel.SelectedDateMeetings.OrderBy(a => a.From).ToList();  
                }  
            }  
        }  
  
  
Please revert us if you have any concern.  
  
Regards,  
Vigneshkumar R 


Loader.
Up arrow icon