SfListView sort descriptors not being executed after item added.

Version 16.3.0.21 - My project is Android only right now, so I'm not sure if this is affecting other platforms.

I have both GroupDescriptors and SortDescriptors added to my SfListView.  When an item is added, the GroupDescriptor is called, and items are grouped appropriately, but the SortDescriptor  comparers are not so items are not sorted within the groups.  I've also tried to RefreshView after item added, but that didn't seem to help.  When the list is loaded, and descriptors added, it does group and sort correctly.  Has anyone else run into this?

Any help will be greatly appreciated.

Sample code to implement issue:

        this.clientListView.DataSource.GroupDescriptors.Add(new Syncfusion.DataSource.GroupDescriptor
            {
                PropertyName = "FirstName",
                KeySelector = (object obj1) =>
                {
                    var item = (obj1 as Client);
                    return item.FirstName[0].ToString().ToUpper();
                }
            });
            this.clientListView.DataSource.SortComparer = new CustomComparer();
            this.clientListView.DataSource.SortDescriptors.Add(new Syncfusion.DataSource.SortDescriptor
            {
                PropertyName = "FirstName",
                Direction = Syncfusion.DataSource.ListSortDirection.Ascending,
                Comparer = new CustomComparer()
            });

    public class CustomComparer : IComparer<object>, ISortDirection
    {
        public int Compare(object x, object y)
        {
            string nameX;
            string nameY;

            //For Contacts Type data
            if (x.GetType() == typeof(Client))
            {
                //Calculating the length of ContactName if the object type is Contacts
                nameX = ((Client)x).FirstName;
                nameY = ((Client)y).FirstName;
            }
            else
            {
                nameX = x.ToString();
                nameY = y.ToString();
            }

            // Objects are compared and return the SortDirection
            if (string.Compare(nameX, nameY, true) > 0)
                return SortDirection == ListSortDirection.Ascending ? 1 : -1;
            else if (string.Compare(nameX, nameY, true) == -1)
                return SortDirection == ListSortDirection.Ascending ? -1 : 1;
            else
                return 0;
        }

1 Reply

JN Jayaleshwari N Syncfusion Team October 22, 2018 12:25 PM UTC

Hi John,  
  
Thanks for using Syncfusion support.  
  
We have checked  your reported query from our side. We would like to let you know that items didn’t refresh in view for that particular group when items are newly added. To refresh an item in view, you need to set LiveDataUpdateMode  
as AllowDataShaping. We have already mentioned this in our datasource documentation, please refer below UG link and sample for your reference.  
  
  
  
public MainPage()  
 
   InitializeComponent();  
   viewmodel = new ContactsViewModel();  
   listView.BindingContext = viewmodel;                                                          
   listView.DataSource.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;  
   listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()  
   {  
      PropertyName = "ContactName",  
      KeySelector = (object obj1) =>  
      {  
          var item = (obj1 as Contacts);  
          return item.ContactName[0].ToString();  
      },  
    });  
    this.listView.DataSource.SortDescriptors.Add(new Syncfusion.DataSource.SortDescriptor  
    {  
          PropertyName = "ContactName",  
          Direction = Syncfusion.DataSource.ListSortDirection.Ascending,  
          Comparer = new CustomComparer()  
    });  
 
  
  
Please let us know if you require any further assistance.  
  
Regards,  
Jayaleshwari N 


Loader.
Up arrow icon