Group on One Attribute Sort by Another.

Contains tips for configurators working with Aware IM
Post Reply
PointsWell
Posts: 1169
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Group on One Attribute Sort by Another.

Post by PointsWell »

New grouping mechanism is a massive improvement on what was previously a rudimentary option.

Is there a way to Group on a field but sort on a totally different attribute?

for example

Code: Select all

Code Type
0    Giraffe
1    Ape
2    Zebra
3    Cat  
If I group on field Code then I would ordinarily get the values in the group header i.e.
0
1
2
3

but I'd like to instead show the Type in the group header, but obviously if I group on name I'd get
Default Grouping / Sort
Default Grouping / Sort
Screen Shot 2021-05-26 at 08.17.13.png (35.45 KiB) Viewed 687 times
Which is not the correct order.

Is there a way to do this? Yes. Thanks for your help Vlad.
Last edited by PointsWell on Wed May 26, 2021 7:18 am, edited 2 times in total.
PointsWell
Posts: 1169
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Group on One Attribute Sort by Another.

Post by PointsWell »

Initialisation Script on query

Code: Select all

config.dataSource.group[0].compare = function (a, b) {
   if (a.items.length == 0)
            return -1;
   if (b.items.length == 0)
            return 1;
   if (a.items[0].SortCode == b.items[0].SortCode)
            return 0;
   if (a.items[0].SortCode > b.items[0].SortCode)
            return 1;

    return -1;
};
Produces this:
Sorted on SortCode Grouped on Type
Sorted on SortCode Grouped on Type
Screen Shot 2021-05-26 at 08.17.25.png (35.63 KiB) Viewed 687 times
See attached model for it in use.
Attachments
GroupSortSolution.bsv.zip
Example
(43.55 KiB) Downloaded 70 times
Post Reply