The function ecx:sort returns entries sorted in ascending or descending order based on the values in a target column. The value returned is an object type.

Example

A related data set includes an updated list of discount fares for popular destinations. This data is inserted into a message and sorted from lowest to highest fare.

The data is stored in an unlinked related data set named Fares, which uses the date the data was imported as the key column. The date used in this example is January 14, 2012. The sort function is constructed as follows:

${ecx:sort(ecx:related('Fares', '01142012'), 'CurrentFare', 'asc')}
CODE

Note that in this example, the function ecx:related determines the key column in the unlinked related data set. Because the key column for this data set is not unique, more than one value can be returned. To insert the sorted data into a message, the function must be set inside a ​ForEach loop. The values shown are set in a table with a column that displays the destination and a second column for the current fare. The HTML that defines the table and inserts the data is constructed as follows:

<table> <tbody> <%ForEach var="count" items="${ecx:sort(ecx:related('Fares','123457'), 'CurrentFare', 'desc')}"%> <tr> <td><% ${count['Destination']}%></td> <td><% ${count['CurrentFare']}%></td> </tr> <%/ForEach%> </tbody> </table>
XML

Structure​

ecx:sort(object, string, string)

Parameters​

Parameter

Description

object

Specifies the source of the data to sort.

string

Specifies the target column to sort. The column sorted does not necessarily have to be the column displayed. For example, you could sort the data according to the purchase date column even if only the price and product name are displayed in the message.

string

Specifies the sort order. If left empty, the default is ascending. To sort in descending order, enter 'desc'. Enter 'asc' to specify ascending sort order.