In This Topic
In order to better organize and present the data in your report, you can sort it alphabetically or numerically in ascending or descending order. You can also use sorting with grouped data to present an easy to understand, comprehensive view of report data.
In a Page or an RDLX report, you can sort data in a data region, in a data grouping, or on a fixed page in a Page report. You can also sort the data directly in the SQL query. In addition, you can also set interactive sorting for your data on a TextBox control.
ActiveReports provides a Sorting page in the dialogs of a data region, grouped data and fixed page to determine where you want to display sorted data.
Sorting Data in a Data Region
In Table and List data regions, you can sort data within the data region. To sort data within these data regions, set sorting in the Sorting page of the specific data region's dialog.
In Tablix, BandedList and Chart data regions, sorting is only possible on grouped data; therefore, there is no independent Sorting page available in their specific dialogs.
Sorting Grouped Data
A Sorting tab is available inside the Groups page of all the data region dialogs and the Detail Grouping page of the List dialog. It allows you to set the sort order of grouped data. This tab is enabled once grouping is set inside the data region.
Sorting on a Fixed Page
In a Page report, sorting is also possible on a fixed page grouped on a dynamic value. Sorting data on a fixed page is similar to sorting grouped data in a data region. The only difference is when you sort data on the fixed page you apply sorting to all the data regions that are placed on the design surface.
Sorting Data via SQL Query
When you connect to a data source and create a data set to fetch data for your report, you define a query. Set the ORDER BY keyword in the query to sort data in ascending or descending order.
By default, the ORDER BY keyword usually sorts the data in ascending order, but you can include the DESC keyword in your query to sort data in descending order. For example, if you want to fetch data from the 'Movie' table of the 'Reels.db' data source and sort it on the Title field, your query looks like the following:
<>SELECT * FROM Movie ORDER BY Title
or
SELECT * FROM Movie ORDER BY Title ASC
In case you want the Title field sorted in descending order, your query looks like the following:
SELECT * FROM Movie ORDER BY Title DESC
Sorting in Data Region
You can set the sorting expression on the Sorting page of the data region dialog. Let us elaborate on the sorting in a data region in a report that uses the 'Movie' table from 'Reels.db' data source on GitHub.
- Right-click the data region and select Properties to open the Properties window. Select the Property dialog link under properties where the commands are displayed to open the data region dialog.
- In the dialog that appears, go to the Sorting page and click the Add(+) icon to add an empty expression to the sorting list below.
- In the Expression field, enter the expression directly or use <Expression...> from the dropdown to open the Expression Editor and select the field on which you want to sort your data.
- Under Direction, select Ascending or Descending to set the order in which to sort your data.
- Click OK to close the dialog.
- From the Report Explorer, drag and drop the field on which the sorting expression is set.
- Preview the report view the result.
Sorting on Grouped Data
You can sort the order of groups through the Sorting tab of the Groups page or the Detail Grouping page of the List data region. The data region is bound to the 'Movie' table from 'Reels.db' data source on GitHub.
Note: In a Chart data region dialog, the Sorting tab is available on the Category Groups and Series Groups pages.
- On the Groups or the Detail Grouping page of the data region dialog, select the Sorting tab.
- In the Sorting tab, click the Add(+) icon to add an empty expression to the sorting list.
- In the Expression field, enter the expression directly or use <Expression...> from the dropdown to open the Expression Editor and select the field on which you want to sort your data. The expression set here should be the same as the grouping expression.
- Under Direction, select Ascending or Descending to set the order in which to sort your data.
- Click OK to close the dialog.
- Preview the report to view the result.
Sorting on Fixed Page
In a Page report, if the fixed page is grouped on a dynamic value, you can sort the order of the groups through the Sorting page of the FixedPage Dialog. Follow these steps to set up sorting on a fixed page in a report bound to the 'Movie' table from 'Reels.db' data source on GitHub:
- Right-click the gray area of the report and select Fixed Layout Settings to open the FixedPage dialog.
OR
Right-click the report page and select Properties to open the Properties window. Select the Property dialog link under properties where the commands are displayed to open the FixedPage dialog.
- In the FixedPage dialog that appears, go to the Grouping page and in the Expression field, enter the expression directly or use <Expression...> from the dropdown to open the Expression Editor and select the field on which you want to group your data.
- In the FixedPage dialog, now go to the Sorting page and click the Add(+) icon to add an empty expression to the sorting list below and in the Expression field enter the same expression you used for grouping the data.
- Under Direction, select Ascending or Descending to set the order in which to sort your data.
- Click OK to close and apply the settings.
- From the Report Explorer, drag and drop the field on which sorting is set.
- Preview the report to view the result.
Note: The difference in setting sorting on a Fixed Page is that it affects every data region placed on the report layout, whereas sorting on a data region is limited to the data region only.
Interactive Sorting
You can add interactive sorting to a TextBox control to allow users to sort columns of data within a data region on a published report.
The interactive sorting feature is set through the Interactive Sort page that is available in the TextBox dialog.
Once you set interactive sorting on a TextBox control, while previewing the report, the textbox control displays a sort icon inside it. A user can sort data that appears inside the textbox in ascending or descending order by clicking the icons.
On the Interactive Sort page of the TextBox dialog you can find the following fields for entering values:
- Sort Expression: An expression specifying the sort value for data contained in the column.
- Data region or group to sort: Select the grouping level or data region within the report to sort. The default value is Current scope, but you may also choose an alternate data region or grouping.
- Evaluate sort expression in this scope: Select the grouping level within the report on which to evaluate an aggregate sorting expression. The default value is Current scope, but you may also choose an alternate data region or grouping.
Set Interactive Sorting on TextBox
Let's set up the interactive sorting in a report that is bound to the 'Movie' table from 'Reels.db' data source on GitHub and displays movies with the title, release year and user rating information. We will add the interactive sorting to the Title textbox, so that you can view the list of movies by the title, changing the descending or ascending order of movies, from A to Z and vice versa.
- From the Toolbox, drag and drop a Table data region onto the report.
- From the Report Explorer, drag fields into the detail row of the table. Labels appear in the table header row, and expressions appear in the detail row.
- Click to select a TextBox in the header row on which you want to allow users to sort, and in the Commands section at the bottom of the Properties Panel, click the Property dialog command.
- In the TextBox dialog that appears, select the Interactive Sort page.
- Select the checkbox next to Add an interactive sort action to this textbox and enable the other properties on the page.
- Under Sort expression, drop down the list and select the expression containing the value of the field on which you want to provide sorting.
Note: Under Data region or group to sort, and Evaluate sort expression in this scope, you can optionally choose a different a scope from the Choose data region or grouping drop down list.
- Click OK to close the dialog and accept the changes.
- Preview the report. At preview, you can see a sort icon next to the TextBox control, the Title header in this case.
You can click the icon to sort in descending order. The icon changes to an up arrow that you can click to sort in ascending order.