Pivot grid column fields sort by subField

Posted by: ralph.ramos on 5 July 2019, 6:09 am EST

    • Post Options:
    • Link

    Posted 5 July 2019, 6:09 am EST

    Hi,

    I have a pivot engine with a rowField (‘Person’) valueField (‘Sales’) and a columnField (‘Weekday’), The column field has the weekdays as values i.e. Monday, Tuesday, etc. This column field also has a subField named WeekdayNo (1 ,2, 3 … 7) which could specify the order of the columns in the pivot grid.

    How can I use this subField to sort the column field because right now, the pivot grid sorts the columnfield by name e.g. “Friday, Monday, Saturday, Sunday…”

    Regards,

    Ralph

  • Posted 8 July 2019, 7:26 am EST

    Hi,

    You may use the sortComparer property of the PivotField class to sort the values in a field. Please refer to the sample below:

    https://stackblitz.com/edit/js-qfcb6a

    API Reference:

  • Posted 9 July 2019, 2:28 am EST

    Hi,

    Thank you for your reply. But the problem is that the actual order of the weeks should not be specified and used to sort the columns.

    
    let weeks = 'Mon,Tues,Wed,Thur,Fri,Sat,Sun'.split(',');
    
    var weekday = ngPanel.fields.getField('Weekday');
    weekday.sortComparer = function(a, b) {
      return weeks.indexOf(a) - weeks.indexOf(b);
    }
    
    

    The requirement is to sort the column field by using the Day.value. As this will be applied to other scenarios, like sorting for the months of the year and custom sorting of other fields.:

    • "

    • “name: ‘Wijmo’, value: 1”

    • “name: ‘Aoba’, value: 2”

    • “name: ‘Xamarin’, value: 3”

    • “name: ‘C1 Studio’, value: 4”

    "

  • Posted 10 July 2019, 6:36 am EST

    Hello again,

    You may still use the sortComparer property for sorting but now you may use the collectionView property of the field to convert the weekday name into week number. Please refer to the updated sample:

    https://stackblitz.com/edit/js-fiunfq

    Please let us know if this solves your issue or otherwise.

  • Posted 11 July 2019, 12:03 am EST

    Hi ashwin,

    Thank you! This worked for us.

    Regards

Need extra support?

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

Learn More

Forum Channels