Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 3.5 KB

change-group-sort-direction-based-on-parameter-telerik-reporting.md

File metadata and controls

59 lines (37 loc) · 3.5 KB
title description type page_title slug tags res_type ticketid
Changing Sort Direction Based on a Parameter in Telerik Reporting
Learn how to dynamically change the sort direction of a group in Telerik Reporting based on a parameter value.
how-to
How to Dynamically Change Sorting Direction of Groups in Reports Based on Parameters
change-group-sort-direction-based-on-parameter-telerik-reporting
parameters, sorting, groups, telerik, reporting
kb
1664543

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

note 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:

  • [Ordering Data]({%slug telerikreporting/designing-reports/connecting-to-data/data-items/ordering-data/overview%})
  • [How to Add Report Parameters]({%slug telerikreporting/designing-reports/connecting-to-data/report-parameters/how-to-add-report-parameters%})

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]({%slug telerikreporting/designing-reports/adding-interactivity-to-reports/actions/sorting-action/overview%}).

See Also

  • [Report Parameters Documentation]({%slug telerikreporting/designing-reports/connecting-to-data/report-parameters/how-to-add-report-parameters%})
  • [Sorting Data in Reports]({%slug telerikreporting/designing-reports/connecting-to-data/data-items/ordering-data/overview%})
  • [Sorting Action in Reports]({%slug telerikreporting/designing-reports/adding-interactivity-to-reports/actions/sorting-action/overview%})