There are a few different functions that can be used to sort and order data in Athennian. These are: orderBy_B
and orderBy_A
. In the past, the sort
function was also used, and may be found in older legacy documents.
What's the Difference?
orderBy_B | orderBy_A |
✅ Sorting alphabetically ✅ Sorting numerically ✅ Sorting structured alpha-numerical data* |
✅ Sorting alphabetically ✅ Sorting mixed string** |
🚫 Sorting mixed string** 129fj029kf, 20932jlsfj3 |
🚫 Sorting numerically as number-type data: 1, 2, 3, 4 as string-type data: '1', '2', '3', '4' |
*When the positions of alpha-numerics are structured (ie. not mixed positionally), orderBy_B will work as expected by first evaluating all the elements in common, then sorting by the unique/differing element. In this example, it will first evaluate the alphabetical value, then sort by the numerical since no difference is found alphabetically.
**Mixed string refers to data that is a combination of alpha-numerics.
💡 When in doubt, use orderBy_B!
If you can't remember which function to use, chances are, orderBy_B will sort how you need.
Syntax
The orderBy_B
and orderBy_A
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 Order
When used without additional syntax, the sorting functions default to ascending order (e.g. “A, B, C“; “0, 1 ,2 ,3“)
{#collectionVariable | orderBy_B:'sortingVariable'}
Sample Share Class Data |
Common - 100 issued and outstanding Class A Special - 25 issued and outstanding Class A Common - 150 issued and outstanding Class B Special - 10 issued and outstanding Class B Common - 150 issued and outstanding Class C Special - 5 issued and outstanding Class C Common - 150 issued and outstanding Preferred - 50 issued and outstanding |
|
Input |
{#shareclasses | orderBy_B:'className'}{className} |
{#shareclasses | orderBy_B:'totalOutstanding'}{totalOutstanding | commaSeparate} {className} shares {/} |
Output |
Class A Common Class A Special Class B Common Class B Special Class C Common Class C Special Common Preferred |
5 Class C Special shares 10 Class B Special shares 25 Class A Special shares 50 Preferred shares 100 Common shares 150 Class A Common shares 150 Class B Common shares 150 Class C Common shares |
Descending Order
To sort in descending order (e.g. “C, B, A“; “3, 2, 1, 0“), you can append ! to the sorting variable:
{#collectionVariable | orderBy_B:'!sortingVariable'}
Sample Share Class Data |
Common - 100 issued and outstanding Class A Special - 25 issued and outstanding Class A Common - 150 issued and outstanding Class B Special - 10 issued and outstanding Class B Common - 150 issued and outstanding Class C Special - 5 issued and outstanding Class C Common - 150 issued and outstanding Preferred - 50 issued and outstanding |
|
Input |
{#shareclasses | orderBy_B:'!className'}{className} |
{#shareclasses | orderBy_B:'!totalOutstanding'}{totalOutstanding | commaSeparate} {className} shares {/} |
Output |
Preferred Common Class B Special Class B Common Class A Special Class A Common Class C Special Class C Common |
150 Class C Common shares 150 Class B Common shares 150 Class A Common shares 100 Common shares 50 Preferred shares 25 Class A Special shares 10 Class B Special shares 5 Class C Special shares |
Advanced Sorting: Secondary Parameter
Both orderBy_B
and orderBy_A
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.
{#shareclasses | orderBy_B:'!totalOutstanding':'className'}
In the above sample code, the shareclasses collection would:
-
be first sorted numerically in descending order by the total number of outstanding shares,
-
then sorted alphabetically in ascending order by class name.
Sample Share Class Data |
Common - 100 issued and outstanding Class A Special - 25 issued and outstanding Class A Common - 150 issued and outstanding Class B Special - 10 issued and outstanding Class B Common - 150 issued and outstanding Class C Special - 5 issued and outstanding Class C Common - 150 issued and outstanding Preferred - 50 issued and outstanding |
Input |
{#shareclasses | orderBy_B:'!totalOutstanding':'className'}{totalOutstanding | commaSeparate} {className} |
Output |
150 Class A Common shares 150 Class B Common shares 150 Class C Common shares 100 Common shares 50 Preferred shares 25 Class A Special shares 10 Class B Special shares 5 Class C Special shares |
Legacy Function: sort
While still present in many legacy documents, we have transitioned away from using the sort
function, which was once used to sort data by date. Where possible, it is recommended to update the template to use orderBy_B
.
Syntax
Refactoring for Chronological Order
When used without additional syntax, the sort
function defaults to ascending or chronological order (from earliest to latest).
{#collection | sort:'dateVariable'}
When refactoring for ascending or chronological order, simply replace sort
with orderBy_B
.
{#collection | orderBy_B:'dateVariable'}
Refactoring for Reverse-Chronological Order
To sort in descending or reverse-chronological order (from latest to earliest), the sort
function takes on specific syntax:
{#collection | sort:'dateVariable':true}
When refactoring for descending or reverse-chronological, the coding syntax must be updated for use with orderBy_B
, like so:
{#collection | orderBy_B:'!dateVariable'}
Sample Director Data |
Aaron Arboretum elected on August 23, 2006 Brittany Botany elected on March 20, 2020 Carlos Chlorophyll elected on May 6, 2017 Daniel Deciduous elected on June 1, 2001 Everett Evergreen elected on November 5, 2012 |
|
Legacy code using sort |
Chronological |
Reverse-chronological |
{#affiliations | sort:'startDate'}{participant_fullName} |
{#affiliations | sort:'startDate':true}{participant_fullName} {/} |
|
Refactoring to orderBy_B |
{#affiliations | orderBy_B:'startDate'}{participant_fullName} {/} |
{#affiliations | orderBy_B:'!startDate'}{participant_fullName} {/} |
Output |
Daniel Deciduous Aaron Arboretum Everett Evergreen Carlos Chlorophyll Brittany Botany |
Brittany Botany Carlos Chlorophyll Everett Evergreen Aaron Arboretum Daniel Deciduous |