How to sort a list of something by something else

In a dispatch app I have a table of Drivers (including each Driver’s geographic address), and a table of Jobs (including each Job’s Pickup address).

At some point (triggered by a button for example) the user needs to pick the n (maybe 6) nearest available drivers to the Job’s address.
So I want to end up with a Repeating Group listing Driver ID ordered/sorted by Distance.

I can see 2 approaches:

  1. In the Current Job: create a list of Driver IDs and a list of Distance for each Driver; use a private plug-in to sort the first list by the second; then display this sorted list along with a check box to allow multiple selections. But how do I display the list? An RG doesn’t seem to lend itself to showing a list of values with a check box against each one.

  2. For each Driver create a single field called Distance. This can then be easily displayed in an RG, ordered by Distance (the ordering being a feature of the RG). But how do I create/modify a single field for all Drivers?

Both approaches seem to have a hurdle that I can’t jump yet!

Any ideas welcomed!

The screen shot below shows Driver ID (column GW) and Distance for a particular Job - but obviously this is not sorted by distance!

46

When you sort based on a location field you can select the “distance from” option. So do a search for drivers and sort their location by distance from the pickup location.

1 Like

Brilliant - thanks! It took a bit of fiddling (I had to delete and re-insert the RG). This is what I get now:
24

If anyone else is interested, this is what the RG expressions look like:

The key thing I just hadn’t seen before is that when you Sort by Address then the Distance from box appears.

21
The RG distance expressions is:

3 Likes