CASE: Use "persistent_id" to sort the "people" drop

Hi there :raised_hand_with_fingers_splayed:,

You might have noticed that the period.people drop is automatically sorted by name in alphabetical order.

For example:

{% fori person in period.people %}
  {% input person.name %}
{% endfori %}

ezgif.com-gif-maker

This is quite handy in most scenarios. However, you sometimes want to sort the names in the order they were entered. We can do this by sorting the collection using persistent_id :

{% addnewinputs %}
  {% assign people = period.people | sort:'persistent_id' %}
{% endaddnewinputs %}

{% fori person in people %}
  {% input person.name %} {{ person.persistent_id }}
{% endfori %}

image

As you can see in the above image, I printed the persistent_id to show how this unique reference is assigned to each name in the drop following the natural enumeration order.

Now, because 1932342 is greater than 1932341, Charlie appears after Zoe.


:information_source: NOTE: You can achieve similar results by using id instead of persistent_id. However, bear in mind that id changes from period to period (i.e. the id number will be different in 2021 than in 2020) so it’s always better to use persistent_id to avoid issues when copying data across different periods.

For example:

2020

image

2021
image

Hope this was useful!

Best,
Borja

1 Like