Sorting and Ordering Data

  • Updated

There are a few different functions that can be used to sort and order data in Athennian. These are: orderBy_A,orderBy_B, and sort.

 

When to Use

Function

βœ…

🚫

orderBy_A

Mixed strings

129fj029kf, 20932jlsfj3

Alphabetical

A, B, C, D

Numeric Sorting

as Numbers

1, 49, 5, 50

as Strings

'1', '49', '5', '50'

orderBy_B

Alphabetical

A, B, C, D

Numeric Sorting

as Numbers

1, 5, 49, 50

as Strings

'1', '5', '49', '50'

Registers

'23', 24, '#-24', '25(r)', '26-R', '#', ''

Mixed strings

a1b3, a2b3, j39jf

❗️When the positions of alpha numerics are not mixed, orderBy_B will work as expected. It will first evaluate the alphabetical value, then the numerical if no difference is found.

C-1, C-2, C-3

sort

Dates

 

orderBy_A, orderBy_B

The orderBy_A and orderBy_B functions enable you to sort variables alphabetically or numerically in a list, either in ascending or descending order. The default within Athennian is to generate the list of variables in the order the data is added to the system, if no sorting function is applied.

Ascending or Descending Order

When used without additional syntax, the orderBy_A or orderBy_B functions default to ascending order (e.g. β€œA, B, Cβ€œ; β€œ0, 1 ,2 ,3β€œ):

orderBy_A:'mixedStringVariable'
orderBy_B:'fieldVariable'

To sort in descending order (e.g. β€œC, B, Aβ€œ; β€œ3, 2, 1, 0β€œ), you can append ! to the variable:

orderBy_A:'!mixedStringVariable'
orderBy_B:'!fieldVariable'

Advanced Sort: Secondary Parameter

Both orderBy_A and orderBy_B are advanced sort methods and can take a second parameter to sub-sort by as a fallback. This means that once the first parameter has been sorted, the secondary parameter will also be evaluated and sorted accordingly. This functionality is particularly useful for registers.

Sample code:

{#directors | orderBy_B:'lastName':'firstName'}

In the above example, the directors collection would:

  • first be sorted alphabetically in ascending order by last name,

  • then sorted alphabetically in ascending order by first name.

Examples

 

orderBy_A

orderBy_B

Sample Dataset

Shareholders:

Nadia Dragonfruit (shareholderID: d5f91b)
Johnny Appleseed (shareholderID: c96r43)
Emily Cherrystone (shareholderID: a11k29)
Robert Bananapeele (shareholderID: b638w8)

Filter

orderBy_A:'shareholderID'

orderBy_B:'!lastName'

Meaning

Sort the data in ascending order by shareholder ID

Sort the data in descending order by last name

Input

{#shareholders | orderBy_A:'shareholderID'}{name} {/}

{#shareholders | orderBy_B:'!lastName'}{name} {/}

Output

(a11k29) Emily Cherrystone (b638w8) Robert Bananapeele (c96r43) Johnny Appleseed (d5f91b) Nadia Dragonfruit

Nadia Dragonfruit Emily Cherrystone Robert Bananapeele Johnny Appleseed

Using a Table

{#shareholders | orderBy_A:'shareholderID'}{lastName}

{firstName}{/}

{#shareholders | orderBy_B:'!lastName'}{firstName}

{lastName}{/}

(a11k29) Cherrystone

Emily

Dragonfruit

Nadia

(b638w8) Bananapeele

Robert

Cherrystone

Emily

(c96r43) Appleseed

Johnny

Bananapeele

Robert

(d5f91b) Dragonfruit

Nadia

Appleseed

Johnny

Using w:p

{-w:p shareholders | orderBy_A:'shareholderID'}{name}{/}

{-w:p shareholders | orderBy_B:'!lastName'}{name}{/}

(a11k29) Emily Cherrystone
(b638w8) Robert Bananapeele
(c96r43) Johnny Appleseed
(d5f91b) Nadia Dragonfruit

Nadia Dragonfruit
Emily Cherrystone
Robert Bananapeele
Johnny Appleseed

Sort

While present in many legacy documents, we are transitioning away from using the sort function in the same way we use orderBy_A and orderBy_B, except in very specific use cases

Although sort is being transitioned out of use, there may be situations where existing code needs to be reviewed and updated. Where possible, it is recommended to update the template to use orderBy_A or orderBy_B.

 

Use Case

The sort function remains the preferred option when we need to sort data by date. The syntax of the function would be:

sort:'dateVariable'

Ascending or Descending Order

When used without additional syntax, the sort function defaults to ascending order (from earliest to latest). To sort in descending (or inverse) order with sort, the boolean true is appended after a colon (:)

sort:'dateVariable':true

This is especially useful when data needs to be sorted in reverse chronological order with the most current information appearing first.

Example

 

Chronological (Ascending)

Reverse-Chronological (Descending)

Sample Dataset

Eleanor Shellstrop - elected March 14, 2019

Chidi Anagonye - elected December 24, 2003

Tahani Al-Jamil - elected July 5, 2012

Jason Mendoza - elected August 31, 2008

Filter

sort:'electedDate'

sort:'electedDate':true

Input

{#directors | sort:'electedDate'}{name}
{/}

{#directors | sort:'electedDate':true}{name}
{/}

Output

Chidi Anagonye

Jason Mendoza

Tahani Al-Jamil

Eleanor Shellstrop

Eleanor Shellstrop

Tahani Al-Jamil

Jason Mendoza

Chidi Anagonye