# Sort a Joined List using a secondary joined list as sort keys

**URL:** <https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [August 13, 2021, 4:16am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412 "2021-08-13T04:16:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 13, 2021, 4:16am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/1 "2021-08-13T04:16:49Z")

</div>

Finally found a reason to have a play with this one 😃

Not sure how useful this will be for others, but @Jeff_Hager might find it of interest.

It accepts two joined lists, and will sort the values in the first list using the values in the second list as sort keys, and will return the sorted list as a single string with the delimiters stripped out.

I had a very specific use case for this, which was to transform a table like this:

 ![Screen Shot 2021-08-13 at 12.08.39 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/5/c56e3942b3f669a725889c2492e4868ff39a7370.png)

into this:

 ![Screen Shot 2021-08-13 at 12.09.39 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/5/15d002738e6d7ea957d410a8ddfda242f49d583a.png)

It takes an optional delimiter as a 3rd parameter. In this case I used `||` in my joined lists as the source data (the dates) contains commas.

 ![Screen Shot 2021-08-13 at 12.09.27 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/7/b7667efc40304bb068908745d94dd2ec197f39ec.png)

[https://mcdarren.github.io/glide-jl-sort-by-keys-advanced/](https://mcdarren.github.io/glide-jl-sort-by-keys-advanced/)

Update: This has been moved to GitHub, and a few more options added. Link has been updated.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 13, 2021, 5:21am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/2 "2021-08-13T05:21:34Z")

</div>

Yessss

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 11:39am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/3 "2022-01-29T11:39:09Z")

</div>

Hi, any chance this stopped working or am doing this wrong?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/a/0adc05793626287c75357b7906afb53f6cd6713d.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/b/bb71770b4018636d13e8f14efc86550578b6e8e5.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/7/b7c9fd6e5278857a52eb81c53d896f447f21dc07.png)

The list is not changed at all - in fact no matter what I type in the Joined List - sort keys it returns the original list

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 11:46am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/4 "2022-01-29T11:46:22Z")

</div>

I haven’t touched it for a long time. It might be that the hebrew text is tripping it up, although I wouldn’t think so.  
Do any of the rows in your “JoinedDataTable” contain commas? That would certainly break it, if they did.

I actually have a “more advanced” version that I use now, that has a few more options. This is the one that I use mostly now. Perhaps you can try this one?

[https://mcdarren.github.io/glide-jl-sort-by-keys-advanced/](https://mcdarren.github.io/glide-jl-sort-by-keys-advanced/)

Update: oh, are you using the one on Replit? I don’t maintain that one anymore, I should take it down. I moved all my code columns to GitHub a long time ago. I’ll update the original post.

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 11:55am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/5 "2022-01-29T11:55:27Z")

</div>

still getting the same list.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/8/d8fd73575b4498d4db6a4781407f5273850bb058.jpeg)

see the sorting number of step down yet it still appears last

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 11:56am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/6 "2022-01-29T11:56:18Z")

</div>

Any chance you can share some sample data with me, and I’ll see if I can debug it?

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 12:09pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/7 "2022-01-29T12:09:52Z")

</div>

sure 🙂  
Template column:

```auto
<tr>
<td style="width:40%">cell4_1</td>
<td style="width:18%">cell3_1</td>
<td style="width:19%">cell2_1</td>
<td style="width22:%">cell1_1</td>
</tr>

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/6/369326c97e7283ea2529cf9006c748eb713c8510.png)

| EX Name | Reps | Sets | Comments | Sort |
| --- | --- | --- | --- | --- |
| Barbell Hip Thrust | 8-10 | 4 | | 1 |
| Knee banded frog thrust | 12-15 | 3 | מייד אחרי התרגיל הקודם | 2 |
| Split Squat | 10 | 3 | כל אימון להתחיל מרגל אחרת. להוסיף משקל | 3 |
| Barbell Sumo Deadlift | 8-10 | 3 | חובה לצלם - להתחיל משקל נמוך | 4 |
| Bent Knee Side Bridge Hip Abduction | 25 | 2 | אם קל לשים משקולת על הירך | 6 |
| Lying Leg-Hip Raise | 20 | 1 | | 8 |
| V-up | 10 | 2 | | 7 |
| Step-down | 12-15 | 3 | | 5 |

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 12:37pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/8 "2022-01-29T12:37:04Z")

</div>

hmm, seems to work fine for me…

 ![Screen Shot 2022-01-29 at 8.35.37 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/3/731754d377524f28bb8d05e3b6566ea08fa19783.png)

 ![Screen Shot 2022-01-29 at 8.35.58 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/4/d4b64551c5d7defa3abd45b85a41294b4b0453ba.png)

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 2:02pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/9 "2022-01-29T14:02:11Z")

</div>

can you screen shot the lists?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 3:07pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/10 "2022-01-29T15:07:44Z")

</div>

I’d share the whole thing, but unfortunately you can’t share apps that use Experimental Code columns.

 ![Screen Shot 2022-01-29 at 11.05.31 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/b/db78b206947c3713b7d0aab799c12cbddb4cad8e.png)

Template for the table rows  
 ![Screen Shot 2022-01-29 at 11.04.43 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/8/f81ede5af3b68f95c10de7b43da503633fec48e4.png)

Joined list of table rows  
 ![Screen Shot 2022-01-29 at 11.04.58 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/f/cf6b9dabc18e6440b759d8213d3ab9fe777b449a.png)

Joined list of the Sort column  
 ![Screen Shot 2022-01-29 at 11.05.15 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/a/0a68e00d5f9cd486ec7cd35553c1251553dbc6ba.png)

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:18pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/11 "2022-01-29T15:18:54Z")

</div>

thats a mystery im doing the exact same here:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/f/2f2417a35e80d642d1dabd4cbe95364993940705.png)  
and i get this  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/c/fc2890596e58b2827031f1f8bd185af617cb3f77.jpeg)

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:20pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/12 "2022-01-29T15:20:06Z")

</div>

could you remove the ex column and share it

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 3:25pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/13 "2022-01-29T15:25:24Z")

</div>

> **[Untitled spreadsheet](https://belligerent-history-3508.glideapp.io/)**

There is a bunch of other junk in the app. It’s just one I use from time to time to experiment with things. So you can ignore all that - just look for the table called “Lin”

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:25pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/14 "2022-01-29T15:25:43Z")

</div>

OHH never mind I got it!!  
I didnt use a comma in the TD joined list becuse HTML dosent need it but the sorting does.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 3:28pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/15 "2022-01-29T15:28:01Z")

</div>

ahah!

Yeah, that’s a bit of a trap. A delimiter is required for it to work. I generally use a double-pipe `||`, because every now and then there might be a comma in the data (dates, for example).

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:29pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/16 "2022-01-29T15:29:01Z")

</div>

New Problem:  
If the Sort is empty the EX column returns blank instead of the original order.  
and if I use a template to replace with 1 for example the sort is DESC

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 3:30pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/17 "2022-01-29T15:30:16Z")

</div>

> [@Lin\_Altshuler](#):
>
> If the Sort is empty the EX column returns blank instead of the original order.  
> and if I use a template to replace with 1 for example the sort is DESC

What is the desired behaviour if the sort row is empty?  
Should the row be ignored, or default to zero, or?

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:32pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/18 "2022-01-29T15:32:48Z")

</div>

I have case where the user doesn’t need to sort the list because he is ok with the order he created the rows. also sometimes he would use sort only on several rows.  
the app behavior is if the sort is empty the list is displayed in the sheet order, and if some rows have a value they appear under the blank sorting rows.  
I would like the joined list to do the same.

added example: some rows with sort

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/e/de03948a4a43a4f39b2576b0f224fa191d7345f2.jpeg)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 29, 2022, 3:36pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/19 "2022-01-29T15:36:21Z")

</div>

hmm, you’ll probably need to create two template columns for the table rows - one with delimiters and one without. Then use an if-then-else column to decide which one to use in the table. If the sort is empty, use the one without delimiters and plug it straight into the table. Otherwise use the one with delimiters and pass it through the experimental code column first.

> [@Lin\_Altshuler](#):
>
> In short to have the default asc will solve it for me

or do that 🤣

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [January 29, 2022, 3:36pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/20 "2022-01-29T15:36:37Z")

</div>

can I fork this and just change the default parameter?

[Next page](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412.md?page=2)
