C1CollectionView.CustomSort

Posted by: john.kiowski on 31 March 2020, 3:51 am EST

    • Post Options:
    • Link

    Posted 31 March 2020, 3:51 am EST

    Can you please provide an example of using C1CollectionView.CustomSort? A short code fragment will do. It’s not apparent to me what you expect us to provide on this interface. I’ve tried passing a custom IComparer implementation without success.

    Thank you,

    John

    
    public class SortAcendingProjectStructureID : IComparer
    {
        int IComparer.Compare(object a, object b)
        {
            ProjectViewModel p1 = (ProjectViewModel)a;
            ProjectViewModel p2 = (ProjectViewModel)b;
    
            return ((new CaseInsensitiveComparer()).Compare(p1.Site.StructureId, p2.Site.StructureId));
        }
    }
    
    // Class to do descending sort on StructureID property
    public class SortDescendingProjectStructureID : IComparer
    {
        int IComparer.Compare(object a, object b)
        {
            ProjectViewModel p1 = (ProjectViewModel)a;
            ProjectViewModel p2 = (ProjectViewModel)b;
    
            return ((new CaseInsensitiveComparer()).Compare(p2.Site.StructureId, p1.Site.StructureId));
        }
    }
    
    SortDescription sortDescr = _CollectionView.SortDescriptions[0];
    
    if (sortDescr.Direction == ListSortDirection.Ascending)
        _CollectionView.CustomSort = new ProjectViewModel.SortAcendingProjectStructureID();
    else
        _CollectionView.CustomSort = new ProjectViewModel.SortDescendingProjectStructureID();
    
    
  • Posted 31 March 2020, 4:20 am EST

    I figured out how to properly set the CustomSort. But when is the best time to apply this? It seems too late to apply it on the SortedColumn handler. I need to be able to apply a different CustomSort, depending on which column is sorted so I can’t set it on creation of the collection view.

    Thanks,

    John

  • Posted 31 March 2020, 7:44 am EST

    One more issue. The CollectionView doesn’t seem to sort columns that are mapped to child objects on my data model. I believe this used to work in the past, but not sure. Regardless, what is the suggested solution to sorting on columns mapped to child object attributes? In the example I provided above, the mapped field is Site.StructureId.

    Thanks again,

    John

  • Posted 31 March 2020, 7:29 pm EST

    Hi John,

    Glad that you were able to implement custom sort. However, to know how to perform custom sort based on the nested properties, please see attached application.

    In the application, the customer sort is performed on the City field of Address property in Employee class.

    >I need to be able to apply a different CustomSort, depending on which column is sorted

    A suitable time to apply the custom sort would be when the column is not sorted. So, with what control are you using C1CollectionView? Please modify the attachment to make it similar to yours, so that we can then further assist you.

    Regards.

    Ruchir

    CustomSort_C1CollectionView.zip

  • Posted 2 April 2020, 8:42 am EST

    Thank you your previous response. But it seems that we need to avoid using the CollectionView altogether for performance reasons in our real-time acquisition system application.

    I’ve implemented custom sorting behavior on the FlexGrid column header sort handler. But it’s not apparent how to force the header to display the ascending or descending template icon after sorting. Is this possible with the FlexGrid?

    Thanks,

    John

  • Posted 15 April 2020, 4:40 pm EST

    Hi John,

    Regarding showing the sort icons with a custom sort logic in C1FlexGrid, I have attached an application. Please refer it for the code.

    Regarding the performance concerns using C1CollectionView: If the performance concern is related to sorting, using a custom sort along with DeferRefresh method should help as suggested here: https://www.grapecity.com/blogs/uwp-flexgrid-performance-review

    Thanks,

    Ruchir

    CustomSort_C1CollectionView.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels