Sorting and Grouping Data : Sorting data : Ways to sort data
 
Ways to sort data
Sort data in one of two ways:
*Specify sorting in the data set query so that the database processes the data before sending the results to BIRT. Databases are efficient at sorting data, especially if they have indexes to optimize sorts. For that reason, use the query to sort data whenever possible.
*Sort data in BIRT. Use this method if the data source, such as a text file, does not support sorting.
How to sort data through the query
1 In Data Explorer, create a new data set, or edit an existing one.
2 In the query text area, write an ORDER BY clause in the SELECT statement. For example, the following statement returns customer information and sorts rows by credit rank, then by customer name:
SELECT Customers.customerName,
Customers.phone,
Customers.creditRank
FROM Customers
ORDER BY Customers.creditRank, Customers.customerName
3 Choose Preview Results to verify the data that the query returns. The rows should be sorted by the fields in the ORDER BY clause.
4 Choose OK.
How to sort data in BIRT
The instructions in this section assume that you already inserted data in a report.
1 In the layout editor, select the table element or list element that contains the data that you want to sort. Property Editor displays the properties for the table or list.
Figure 9‑4 shows an example of a selected table and the table’s general properties.
Figure 9‑4 Properties for a selected table
2 In Property Editor, choose the Sorting tab.
3 In the sorting page, shown in Figure 9‑5, choose Add to specify the criteria on which to sort the rows.
Figure 9‑5 Sorting page of Property Editor
4 In New Sort Key, specify the following information:
1 In Key, complete one of the following steps:
*To specify a field to sort by, select a field from the drop-down list.
*To specify an expression by which to sort the data, choose the expression builder button, then provide an expression.
2 In Direction, specify the sort order by selecting Ascending or Descending.
3 In Locale, select a language. The language determines the sorting, or collation, attributes that conform to local conventions. Select Auto to sort data according to the locale set on the user’s machine.
4 In Strength, select a collation strength, also known as a collation level. The collation strength determines whether accent marks, case, or punctuation are considered when sorting strings.
Figure 9‑6 shows an example of a sort definition.
Figure 9‑6 Sort expression in New Sort Key
Choose OK. The Sorting page displays the sort key that you defined for the selected table or list.
5 Preview the report. The data in the details section appears in a different order.