Add item to new group

Hello,

lets say i have a grouped and sorted SfListView, the data is grouped by date and sorted by time.

Now when i add a new item with an date that not existed previously in my bound ItemsSource a new group will be added with my item at the bottom of the SfListView instead of where it should be.


So if i have this:

  • 24 Nov. 2021
    •   15:30
    •   16:30
  • 26 Nov. 2021
    •   10:00


and i add a new item for the 25.11.2021 at 8:00

i get this:

  • 24 Nov. 2021
    •   15:30
    •   16:30
  • 26 Nov. 2021
    •   10:00
  • 25 Nov. 2021
    •   08:00


What can i do to get list correctly sorted?


Regards,

   Kalle


1 Reply 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team December 3, 2021 06:29 AM UTC

Hi Kalle, 
 
Thank you for using Syncfusion support. 
 
We have checked the reported query “Add item to new group” from our side. We would like to let you know that you can achieve your requirement by using the GroupComparer to sort the groups based on custom logic. 
 
Please refer to our user guidance document regarding the same in the following link, 
 
Please refer to the following code snippets to achieve your requirement, 
 
CustomGroupComparer 
public class CustomGroupComparer : IComparer<GroupResult> 
{ 
    public int Compare(GroupResult x, GroupResult y) 
    { 
        // Your compare logic here 
 
        return x.Key.ToString().CompareTo(y.Key.ToString()); 
    } 
} 
 
 
Set the CustomGroupComparer to the DataSource.GroupDescriptors. 
ListView.DataSource.GroupDescriptors.Add(new GroupDescriptor() 
{ 
    PropertyName = "ContactName", 
    KeySelector = (object obj1) => 
    { 
        var item = (obj1 as Contacts); 
        return item.ContactName[0].ToString(); 
    }, 
    Comparer = new CustomGroupComparer() 
}); 
 
 
You can also refer to our online documentation to sort the items with grouping from the following link, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
  
 


Marked as answer
Loader.
Up arrow icon