The Sort Filter
The Sort Filter sorts data rows in a datalayer element, giving youcontrol over the sort sequence of the data. This topic discusses the use of this element.
- About the Sort Filter
- Applying the Sort Filter
About the Sort Filter
The Sort Filter element's behavior is similar to the ORDER BY clause in a SQL statement but, unlike a query, it's applied to data after it's been retrieved into the datalayer. The Sort Filter is available to all datalayer elements and is especially useful for non-SQL datasources, such as DataLayer.XML and DataLayer.Web Service.
Dynamic Sorting
The Sort Filter element has an Include Condition attribute:
If the value of this attribute is left blank or contains a formula that evaluates to True, the element is applied to the datalayer. If the value evaluates to False, the element is ignored and does not affect the datalayer. This powerful feature allows you to dynamically determine if the datalayer will be sorted or not.
Applying the Sort Filter
The following examples illustrate how the Sort Filter can be used:
The table above shows the data as it appears in the datalayer, without any sorting. Note the order of the ProductName column data. Now let's sort that column:
- As shown above, add Sort Filter element beneath a datalayer element.
- Set its Sort Column attribute value to the name of the column in the datalayer, ProductName, that the sort will be based on.
- The optional Data Type attribute value, which defaults to Text, specifies the data type of the column being sorted on and, to avoid any ambiguity, should always be set if the column data type is Number or Date.
- The optional Sort Sequence attribute value, which defaults to Ascending, can be set to Descending if desired.
When the report is run again, the data will now be sorted in Ascending order on the ProductName column, as shown above.
- If a second datalayer column is added to the first in the Sort Column attribute value, separated by a comma as shown above, the sort will occur on multiple columns.
The data will now be sorted first on one column and then on the second, as shown above.
However, what about situations in which the columns to be sorted are not the same data type and/or need to be sorted in opposite directions (one in Ascending order and one in Descending order)?
- In that case, additional Sort Filter elements can be used, one for each column, as shown above.
The order of the two Sort Filter elements in the element tree is significant. In this example, the second Sort Filter has been added above the sort filter for CategoryName.
And the data will now be sorted in ascending order on one column and then in descending order on the second, as shown above.
The Sort Filter is very useful and can be added before or after grouping, datalayer links, and other elements to produce different data sets.