This function returns a result sequence from sorting a sequence of Hash-type objects.
Sorting can be in ascending or descending order. It is performed according to the values of an object attribute. To do this, the attribute name or sequence of attribute names representing the path in dot notation leading to the sub-level object attribute needs to be specified.
When the indicated attribute values are String type, locale-based sorting is applie
Unlike lexicographic sorting which compares the coding value of each character, this sort uses a collation which enables two character strings to be compared according to a given language.
NB:
Some differences in relation to the FreeMarker "built-in" "sort_by" function (click here for more details) applied to a ([?]?sort_by) sequence and the "lexicographicSortBy" function:
- The result obtained from the three "sort_by", "lexicographicSortBy" and "localeBasedSortBy" functions is identical for Boolean/Number/Date/Time/Date-time types. For the String type, the FreeMarker "sort_by" function applies a sort using a collation (so a result identical to "localBasedSortBy" but different from "lexicographicSortBy"),
- The "sort_by" function does not sort in descending order. The only solution is to use the FreeMarker "reverse" ([?]?sort_by()?reverse) function, but the original order of equal values is not respected.
Parameters
Hash sequence |
seqHash |
Hash object sequence to sort |
Mandatory |
String/String Sequence |
sedAttrName |
Object attribute on which to apply the sort. It is identified by its name or attribute name sequence representing the path in dot notation leading to it. |
Mandatory |
Boolean |
ascendingOrder |
"true" for an ascending sort, "false" for a descending sort |
Optional. The default value is "true" |
Hash |
collatorInfos |
Definition of collation information. This object can have the following attributes:
|
Optional. If this object is not provided, the locale taken for sorting is that entered for template execution ("strength" and "decomposition" attributes will have a default value which depends on the locale). |
For example
<#assign elegance = [ {"value": "Élégance"}, {"value": "Elegance"}, {"value": "elegance"} {"value": "élégance"}, {"value": "elegANCE"}, {"value": "elègance"} ]> <#-- Sorted by value --> <#list hardisCode.localeBasedSortBy(elegance, 'value', {'locale': 'fr_FR', 'strength':'primary'}) as aObj> - ${aObj.value} </#list> ?
The output is:
- Élégance
- Elegance
- elegance
- élégance
- elegANCE
- elègance
Another example
<#assign elegance = [ {"value": "Élégance"}, {"value": "Elegance"}, {"value": "elegance"} {"value": "élégance"}, {"value": "elegANCE"}, {"value": "elègance"} ]> <#-- Sorted by value --> <#list hardisCode.localeBasedSortBy(elegance, 'value', {'locale': 'fr_FR', 'strength':'tertiary'}) as aObj> - ${aObj.value} </#list>
The output is:
- elegance
- elegANCE
- Elegance
- elègance
- élégance
- Élégance
↑ Top of page