Multiple grouping doesnt respect order of the list

If I have 2 layers of grouping, It doesnt respect my sorting in the viewmodel. For example, below code is sorting the view model by datecreated descending and first group is year. Although first element in the list has datecreated with year 2018, my first group in the view is 2017 and 2018 at the bottom. I tried to add data:SortDescriptor  as well but it didnt change anything. I expect first group year to be 2018


VIEW:

   <sfListView:SfListView x:Name="list"                              
                            ItemsSource="{Binding Logs}"    
              SelectedItem="{Binding SelectedItem, Mode=TwoWay}"  AllowGroupExpandCollapse="True"        
                             SwipeOffset="250"  BackgroundColor="White" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                           SelectionMode="Single"   ItemSpacing="1"  IsStickyHeader="False" IsStickyFooter="False"   ItemHolding="list_ItemHolding"
                                           SwipeEnded="ListView_SwipeEnded" Swiping="ListView_Swiping"
                   AllowSwiping="True" IsEnabled="True"   GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}">
                        <sfListView:SfListView.DataSource>
                            <data:DataSource>
                                <data:DataSource.SortDescriptors>
                                    <data:SortDescriptor PropertyName="DateCreated" Direction="Descending"/>
                                </data:DataSource.SortDescriptors>
                                <data:DataSource.GroupDescriptors>
                                    <data:GroupDescriptor PropertyName="Year" />
                                    <data:GroupDescriptor PropertyName="WeekNo" />
                                </data:DataSource.GroupDescriptors>
                            </data:DataSource>
                        </sfListView:SfListView.DataSource>                        

 VIEW MODEL:
      public ObservableCollection<Log> Logs { get; set; }
  Logs = new ObservableCollection<Log>(AllLogs.OrderByDescending(e => e.DateCreated).ToList(););
  
  MODEL:
 public class Log  
 {
     public DateTime DateCreated { get; set; }
  
     private int weekNo;

        public int WeekNo
        {
            get
            {
                if (weekNo == 0)
                {
                    weekNo = Helpers.GetIso8601WeekOfYear(this.DateCreated);
                }
                return weekNo;
            }
            set { weekNo = value; }
        }

        private int year;

        public int Year
        {
            get
            {
                if (year == 0)
                {
                    year = this.DateCreated.Year;
                }
                return year;
            }
            set { year = value; }
        }
 }

5 Replies

MK Muthu Kumaran Gnanavinayagam Syncfusion Team January 8, 2018 01:51 PM UTC

Hi Emil, 
 
We have checked your requirement “Need to sort the first level group” and referred the attached code snippets from our side. We would like to inform you that the PropertyName you have used for SortDescriptor is different from the PropertyName bound to GroupDescriptor. When both the PropertyName are same then that particular group will be sorted and thus the first level group does not sort its GroupHeader items. So you need to bind the “Year” property to the SortDescriptor PropertyName in your sample to achieve your requirement. 
 
For your assistance, we have attached the sample and you can download it from the below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 



EM Emil January 8, 2018 01:57 PM UTC

Hi,

yes this way works but my original question is using without SortDescriptors. I expect that it should already group it as it was sorted. because I am already sorting in the viewmodel. Isnt it that it should keep the original sorting order when it is grouping it?
thanks,

Emil

<sfListView:SfListView x:Name="list"                              
                            ItemsSource="{Binding Logs}"    
              SelectedItem="{Binding SelectedItem, Mode=TwoWay}"  AllowGroupExpandCollapse="True"        
                             SwipeOffset="250"  BackgroundColor="White" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                           SelectionMode="Single"   ItemSpacing="1"  IsStickyHeader="False" IsStickyFooter="False"   ItemHolding="list_ItemHolding"
                                           SwipeEnded="ListView_SwipeEnded" Swiping="ListView_Swiping"
                   AllowSwiping="True" IsEnabled="True"   GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}">
                        <sfListView:SfListView.DataSource>
                            <data:DataSource>                              
                                <data:DataSource.GroupDescriptors>
                                    <data:GroupDescriptor PropertyName="Year" />
                                    <data:GroupDescriptor PropertyName="WeekNo" />
                                </data:DataSource.GroupDescriptors>
                            </data:DataSource>
                        </sfListView:SfListView.DataSource>


MK Muthu Kumaran Gnanavinayagam Syncfusion Team January 9, 2018 05:55 PM UTC

Hi Emil, 
 
We have sorted the underlying collection in the ViewModel and bound that collection to ItemsSource of SfListView without using SortDescriptors. We have found that the collection is sorted properly and based on those items, the groups are also sorted in descending order in the View. 
 
Can you please check whether the items are sorted in your collection(Logs) which is bound to ItemsSource of SfListView. If this collection is sorted, then the groups will be sorted automatically. 
 
For your assistance, we have attached the sample and you can download it from the below location. 
 
 
If the above solution does not satisfy your query, please modify the attached sample to replicate the reported issue which helps us to understand and resolve it at our end. 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 



CH cherry May 14, 2018 06:46 AM UTC

Hi,

I also encounter this issue. The same scenario, I order the itemssource on the viewmodel. The ordering is correct on the first load but after refreshing the itemssource, the list gets reordered alphabetically according to the header key. 


Best regards,
Cherry


RS Rawoof Sharief Muthuja Sherif Syncfusion Team May 14, 2018 08:30 AM UTC

Hi Cherry, 
 
We have checked the reported query from our end.  We would like to inform you that the PropertyName you have used for SortDescriptor and GroupDescriptor are same then the Items and group header will be sorted. If both the property are different, groups are not sorted but the sorting will be based on the property name specified in the sort descriptor.. 
 
Regards, 
Rawoof M. 


Loader.
Up arrow icon