sortComparer is not executed - Angular4

Posted by: saso.sabotin on 12 October 2017, 9:12 pm EST

    • Post Options:
    • Link

    Posted 12 October 2017, 9:12 pm EST

    Hi!

    I have an issue sorting my list. When I attach the method to the ‘sortComparer’ property in CollectionView, I expect the method to be executed but it’s not. The only way I can achieve sorting is by putting the conditions into ‘sortDescriptions’ array which is also part of the CollectionView. The ‘filter’ method is working but ‘sortComparer’ is not. Am I missing something there?

    I am using Angular4 with Typescript.

    This works:

    
    dataList.filter = this.filterExecute.bind(this);
    
    

    but this doesn’t:

    
    dataList.sortComparer = this.sortExecute.bind(this);
    
    

    Can you help me with that?

    Thank you very much!

  • Posted 15 October 2017, 9:06 pm EST

    Hi,

    We are looking into this. I will update you regarding this soon.

    Thanks,

    Abhishek

  • Posted 17 October 2017, 8:10 pm EST

    Hi,

    Can you provide a working sample?

    ~nilay

  • Posted 17 October 2017, 10:22 pm EST

    Yes. Here you go.

    sorting.zip

  • Posted 22 October 2017, 5:00 pm EST

    Any news regarding that issue?

    Thanks!

  • Posted 22 October 2017, 10:11 pm EST

    Hi Saso,

    SortComparer property stores the function used to compare values when sorting. It does not automatically sort the data. To sort the array you would have to add a sort descriptor. The correct way to do this is by adding SortComparer first and pushing values in SortDescriptions later.

    This is the updates I have performed in your sample:

    constructor() {
    
        this.data = new wjcCore.CollectionView(this.getData(20), {
            sortComparer: (a, b) => {
                console.log('sortComparer IS REACHABLE');
                return 0;
            },
            sortConverter: (a, b) => {
                console.log('sortConverter IS REACHABLE');
                return 0;
            }
        });
        setTimeout(() => {
            console.warn('SORTING');
            this.data.sortDescriptions.push(new SortDescription('Amount', true));
            
        }, 300);
    }
    

    Let me know if there are some confusions.

    ~nilay

  • Posted 23 October 2017, 6:38 pm EST

    This is executing it.

    Thank you a lot! :slight_smile:

Need extra support?

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

Learn More

Forum Channels