Group by a different field to group title

4 posts, 0 answers
  1. Andre
    Andre avatar
    3 posts
    Member since:
    Nov 2016

    Posted 02 Feb 2017 Link to this post

    Hi guys, I've a case where I'm grouping with the grid, but want to sort in a different order.

    E.g. by default if my group data field has values A, B, C, D this would be the group order.

    I have data that is sorted by sections of data, that have an order the client wants displayed in a priority order.

    To simplify it something like:

    Display Field Value    Sort Field Value

    A                                2

    B                                4

    C                                1

    D                                3

    I want the grouping text to be A, B, C, D, but the order to be C, A, D, B as per the sort field value (a field not to be visible).

    I haven't been able to find anyway to do this. Any help greatly appreciated.

  2. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    1285 posts

    Posted 06 Feb 2017 Link to this post

    Hello Andre,

    In general, the groups in a grouped Grid can be sorted only ascending or descending based on the default sorting for the respective column field.

    You can achieve the desired behavior by some custom implementation, for example using a column template to show one field's value in a column, bound to the field you would like to sort by, and the columns.groupHeaderTemplate to provide a function that will retrieve the desired information for the group header, e.g.:

    http://dojo.telerik.com/OYegi/2

    However, please mind that this approach is not supported, and may have some undesired side effects. I can recommend the Progress Professional Services for any feature customization or custom implementation:

    https://www.progress.com/services/outsourcing/feature-customization

    Let me know if you are interested, and I will arrange for someone from the team to contact you.

    Regards,
    Dimiter Topalov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Revati
    Revati avatar
    1 posts
    Member since:
    Aug 2018

    Posted 23 Aug 2018 in reply to Dimiter Topalov Link to this post

    Hi Dimiter, could you please provide an example of the above? I want to group by Country and sort by the count of states in each country. How can that be achieved?
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 28 Aug 2018 Link to this post

    Hi Revati,

    The dojo example in the previous post shows how to bound a column to one field, but display another field`s values in it. In your case, you will need another field in the dataItems that will be used for grouping and sorting the records as per your requirements (maybe CountryOrder). However, since the number of states could be equal for different countries, you might need to create a value with the number of states as prefix and the country name as suffix and populate it for each record in the database. Once that field is added to the records, you could bound the column to the CountryOrder field and group by it. Using the templates you can show the Country field values.


    Regards,
    Konstantin Dikov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top