The not possible sort repeating group by

OK, I’ve read everything I can find on sorting RGs, I’ve looked at BDK plugins for RG’s and @keith fantastic list shifter plugin. But alas… I still can’t find away to achieve the following.

Hypothetical Scenario.
I have a Datatype called “Houses”, with a field called “Colour”
And a second datatype called “Paint” with a field called “Colour”

I’m displaying “Paint” in a repeating group and want to sort the Paints based on
how many “Houses” have a particular “Colour”. Something akin to sorting the paints by popularity.

In my head, it would go something like making a list of the number of houses of a specific colour;
(I believe this is possible with list shifter)

Houses
Red = 7
Green =4
Blue = 1

…And then filter/sort the “Paints” in the RG by the value of “Houses’s” “Colour” that corresponds to the Cell’s “Paint’s” “Colour”.

So now the RG’ will show Red, Green, Blue.

Perhaps this simply is not possible in any way, shape, or form, and I should just give up.

1 Like

Hi there, @casheets123… what you are trying to do is definitely possible, and I’m guessing there are multiple ways to go about it.

paint1

One way that came to my mind (and that produced the repeating group above) is to have a houses field (with a field type of number) in the Paint data type. This field is simply a count of the number of houses that have a particular paint colour. So, when a house is added with the colour red (the colour field in the Houses data type has a field type of Paint), you include a workflow step that increments the houses field for the colour red by one.

With that structure in place, the repeating group sort is as simple as it gets…

Think something like that could work for you?

Best…
Mike

1 Like

Thanks Mike,

I forgot to mention in the initial post that the Paint data type already has a couple of thousand user entries. So I’ve been looking for a way to achieve it without adding Data to those entries.

I could go down the route of changing all those paint entries of course. But it’s something I’ve been hoping to avoid. :wink:

Eh, you haven’t lived until you’ve backfilled data in production… quite a rush! :slight_smile:

2 Likes

Haha quite. I’ve done it once before and it was a butt clenching experience for sure. But I guess I should mentally start preparing myself at this point.

1 Like

Yeah, you can do this entirely in List Shifter. The sort action there lets you sort a Thing based on another set of values that are not on the Thing itself.

I’m working up an example of this, but the technique is like I describe in the “Concert Goers” example (search that).

Oh? that’s fantastic…

I did start building something using the concert goer example (fun read btw) but I either got
too lost or couldn’t figure out how to adapt it. If I remember it correctly, the concert goer example was shifting only one list and sorting on? But I might be remembering this wrong. An example would be bloody amazing!

Hey @casheets123, I made exactly the demo scenario you described. I’ve not made a video explaining this yet, but see my text on the page and examine the editor to get an understanding of how its done.

While doing this, I realized that it was WAY harder (in this exact example) to figure out how to turn the list of Paints into a list of counts of those Paints than it should be. So, I did it the hard way first (that’s the link I share here) and then I updated List Shifter with a new function that makes this 10 times easier to understand. I’ll link to a new version using that feature later.

But in the mean time check this out:

And here’s the editor:

More on this later.

-K-

1 Like

And @casheets123, here’s the slightly different way of doing it (different, easier to understand algorithm in PROCESS List):

Runtime: https://list-shifter-demo.bubbleapps.io/version-test/mapped-sort-simpler-count?debug_mode=true

1 Like

Thanks @keith,

I’ve spent half the day here trying to recreate this for my specific (actual) scenario. And repeatedly failed of course haha. The first reason being, I’m too daft to figure out the magic going on in List shifter. I then quickly realized that what I probably want to achieve in reality, is not showing
the Paints shifted as the end result, rather houses. That might sound a bit backward, so please bare with me here.

And I think I need to give a better example, Let’s do credit cards/loyalty cards and reward currencies.

The user will have a number of cards, each card has a reward currency with X amount of points. Several cards can have the same currency, so the user can create a “bucket” with these cards to see all the points of a particular currency. Let’s call this data type “rewards”.

These rewards are then shown in a RG, and this RG is sorted by how many cards a user has in each currency.

I’m sure the answer to set this up is in there somewhere, and list shifter is fully capable to handle this. but I’m just too stupid to see it. But it feels like it should be a very similar set up?

I bashed up a quick example to illustrate here.

Anyway, I got you some Coffee and Cigarettes for spending time on this endeavour after I sent
you on a wild goose chase with painted houses. Sorry about that, hopefully someone else will find it useful as well :slight_smile:

1 Like

Thanks for the contribution! I really will be doing a video going over this sort of scenario, and talking through it will surely help you understand.

The basic concept is:

  • You have some array (list) that you want to sort by some property. (Put this list in List Shifter.)

  • All you need to do the sort is to have a same-sized, same ordered list representing the property that you want to sort on.

  • If you can write an expression that gives you that list, you’re done. Just use that expression in List Shifter’s sort action.

  • Your sorted list appears at List Shifter’s Shifted List output.

Now, sometimes (as in the example I built), you CANNOT build an expression to get the list you need in bullet three. So you have to construct it.

This topic was automatically closed after 70 days. New replies are no longer allowed.