SORT and SORT_NATURAL functions

When you're displaying data in pages, order matters. An alphabetically sorted list of departments is easier to read than a random jumble. A chronologically arranged set of incidents enables users to find what they need more quickly. Sorted data looks professional, intentional, and user-friendly.

Tines gives you two sorting functions: SORT and SORT_NATURAL. Both organize arrays, but they handle capitalization differently. Understanding when to use each will help you present clean, predictable data to your users.

What SORT does 

SORT arranges elements in an array based on a specified property. If you're sorting an array of objects (like incidents or users), you tell SORT which field to sort by. If you're sorting a simple array of text values, SORT arranges them in order.

Here's the key characteristic of SORT: It's case-sensitive. Capital letters come before lowercase letters in the sort order. This means "Apple" will appear before "apple" because uppercase A comes before lowercase a in character ordering.

What SORT_NATURAL does 

SORT_NATURAL works similarly to SORT, but it's case-insensitive. It treats "Apple" and "apple" as equivalent when determining order, sorting them alphabetically regardless of capitalization. This creates a more intuitive, human-friendly sort order.

For most page-building scenarios, SORT_NATURAL is the preferred option. It produces results that match how most users expect alphabetical lists to work.

The basic syntax 

Both functions use the same syntax:

SORT(array, path)
SORT_NATURAL(array, path)

For simple arrays of text or numbers, you only need the array:

SORT(priorities)
SORT_NATURAL(team_names)

For arrays of objects, you specify the path to the field you want to sort by:

SORT(incidents, "title")
SORT_NATURAL(users, "name")

Sorting example: Organize continents 

Let's look at an array of continents:

{
  "continents": [
    "Americas",
    "europe",
    "Asia",
    "africa"
  ]
}

Using SORT:

SORT(action_name.continents)

The SORT output:

["Americas", "Asia", "africa", "europe"]

The capitalized regions ("Americas", "Asia") come first because uppercase letters sort before lowercase in SORT.

However, if we use SORT_NATURAL instead on the same data:

SORT_NATURAL(action_name.continents)

The SORT_NATURAL output:

["africa", "Americas", "Asia", "europe"]

SORT_NATURAL ignores case, so it sorts purely alphabetically.

Was this lesson helpful?

Built by you,
powered by Tines

Already have an account? Log in.