New to Telerik Reporting? Download free 30-day trial

Changing Sort Direction Based on a Parameter in Telerik Reporting

Environment

Version Product Author
Telerik Reporting Desislava Yordanova

Description

Learn how to change the sort direction dynamically of a group within a report based on the value of a parameter. The group should be sorted either in descending order or ascending order.

Solution

To dynamically control the sort direction of a group based on a parameter, follow these steps:

  1. Define a report parameter with the appropriate value type, for example, SortByDirection. This parameter will be used in the expression for sorting the data to achieve interactivity. The AvailableValues are: 'ASC' and 'DESC'.

    SortByDirection Report Parameter

  2. In the report designer, navigate to the report properties. Then, the SortByDirections parameter can be used for the report's Sortings collection:

    Sortings Collection

    Edit Sorting

    The idea is to introduce two Sorting rules, with 'ASC' and 'DESC' order, and apply sorting by only one of them, with the corresponding order.

    For example, when the user selects ASC for the SortByDirections parameter, we apply proper Sorting Expression for the corresponding ASC rule. In this case, the Sorting Expression for the DESC rule returns Null (or other constant), guaranteeing no change in the data order caused by it. This way, the sorting is done in ascending order.

  3. Apply the changes and preview the report. The sorting direction of the specified group will change based on the value of the SortByDirection parameter.

    Preview Sorting Result

A sample report can be found in the Sample Reports folder >> Sorting and Filtering with Report Parameters.trdp.

For more information on sorting data in reports and using report parameters, refer to the following Telerik Documentation articles:

Notes

  • Interactive sorting, allowing users to toggle between ascending and descending order (without any parameter), can also be achieved using sorting actions. For more details, see Sorting Action Overview.

See Also

In this article