No way to set sort on cardview through code

I and trying to set a starting sort direction on one groupinfo but it don't matter if I find the matching one and set it  to sort direction ascending or clear them and add a new one the card view is unsorted at start see examples below. the card items will only become sorted if I click on the SiteLocationName field in the top right corner of the image, i have even tried triggering the methods below after the whole page is loaded using a button and still no effect.

private void OnBayList_Loaded(object sender, RoutedEventArgs e)
        {

            OnBayList.GroupCards("SiteRegion");
            OnBayList.GroupNames.Clear();
            OnBayList.GroupNames.Add(new GroupInfo() { Name = "SiteLocationName", SortDirection = SortingDirection.Ascending });
        }
private void OnBayList_Loaded(object sender, RoutedEventArgs e)
        {

            OnBayList.GroupCards("SiteRegion");
            var namehead = OnBayList.GroupNames.Single(i => i.Name.Equals("SiteLocationName"));
            namehead.SortDirection = SortingDirection.Ascending;
        }



3 Replies 1 reply marked as answer

BR Bharathi Rajakantham Syncfusion Team May 13, 2021 12:58 PM UTC

Hi David, 
 
Thanks for contacting Syncfusion Support. 
  
We checked your query “Sort Card view items” from our end. Prepared a sample based on your requirements. In our sample, we sorted the card view items programmatically by date field using ICollectionView SortDescriptions. Please find the code snippet,and sample for the same.  
 
 
Code Snippet: 
 
_collectionView = CollectionViewSource.GetDefaultView(cardView.ItemsSource) as ICollectionView; 
_collectionView.SortDescriptions.Add(new SortDescription("DOB", ListSortDirection.Ascending)); 
 
 
Output: 
 
  
Please let us know if you need any further assistance on this. We will be glad to assist you. 
 
Regards, 
Bharathi R 


Marked as answer

DC David Carter May 17, 2021 09:41 AM UTC

Thanks
     While that worked it does seem off that there are options in that other place to set sorting which don't work, would it not be worthwhile removing those extra options to prevent confusion over how to achieve something.


SG Sangeetha Ganesan Syncfusion Team May 18, 2021 06:04 PM UTC

Hi David,    
  
Thanks for the update 
 
We can’t replicate the reported issue ” Sorting does not work on other places ” from our end. We have created a simple sample based on your requirement. Please check the sample for your reference . If we misunderstand your query, please share the replication steps and make our sample to issue reproducible to proceed further and this. It will help us for provide a prompt solution on this.  
 
 
Regards, 
 
Sangeetha G 


Loader.
Up arrow icon