Sort HTML List

I’ve successfully created a method for emailing an HTML formatted listed of items from my Glide App, based on general the approach described here (except that instead of the resulting output being a list of comma separated values, it is a list of values surrounded by html tags).

Everything works as needed EXCEPT the bulleted list is not sorted in the order I need it to be sorted in. It is sorted in the order that the selected items appear in the Glide table they are drawn from. Unless I’m mistaken, you can’t sort a Glide Table in the data editor (if I’m wrong, let me know because that would probably solve my problem).

So, I’m trying to figure out how to sort the list before it is delivered through Make to the body of the email. I tried various ways of using sort Array to change the order of the items in the relation, but that did not work.

Unless there is another solution, I’m thinking I would use a javascript column to sort the list items (each of which are surrounded by an < li > tag) and use that column as the output for the email. I’m pretty much a complete javascript novice, so although there are lots of examples online of javascript code to sort an html list, I can’t seem to get anywhere close to implementing them in Glide to accomplish this.

So my questions:

  1. Is there a better solution to my problem than using javascript?
  2. If not, any guidance on how to implement this in Glide would be great. I’m not totally sure how to implement the javascript column. For example, this is a pretty straightforward example I found online but I don’t know how to adapt it in the Javascript column.

var listItem = document.getElementById(‘list’).getElementsByTagName(‘li’);
var listLength = listItem.length;
var list = ;
for(var i=0; i<listLength; i++)
list[i] = listItem[i].firstChild.nodeValue;
for(var i=0; i<listLength; i++)
listItem[i].firstChild.nodeValue = list[i];

Same boat here last year. I had to use JavaScript to sort in my case. It would have been nice if relation/lookup allows us to sort based on a column.

Are you trying to sort based on a date/time value, a numeric value, or alphabet order?

1 Like

Alphanumeric, like AB4328. Did you find a solution?

I agree on the feature request. We need that.

:wave:numeric… looking for the same advice

Does it always start with a character, or can it be numeric sometimes? If it can be numeric, which should you put first?

it always starts with a character. So it should first give me all the ABxxxx. Then all the BCXXXX

Hi @ThinhDinh. Do you have any guidance on this?

Sorry I haven’t had time to craft up an example. When I do, I’ll let you know.

1 Like

Of course. I am very thankful for you and all the experts on here.

This isn’t a great solution, but I have a fairly static list that I recently updated and wanted to re-sort it, so I ended up doing this:

  • Export the data to csv
  • Open in a Google sheet and sort the data there
  • Save as a csv
  • Delete the lines of data in your Glide table
  • Import the sorted csv back into the table.

This obviously wouldn’t work for a table that is frequently updated, but for something modified less often it is a decent workaround until Glide comes up with a way to sort our tables.

(it also is a solution for those of us who don’t want to learn Javascript)