Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

3.12 Sorting the Grouping Data

Sorting the Group Data

After creating the groups and running a test report, you may notice that although your groups are fine, the detail rows within the group are out of order. They might appear to be printed randomly or their natural sort order isn’t how you want it sorted. For example, in Figure 3-15 the detail records are sorted naturally by Employee ID but you want them sorted by Last Name.



Figure 3-15. Detail records that aren’t sorted on the right field.

Sorting the detail records is done separately from sorting the grouping records. Telling the report how to group data doesn’t mean that it knows which fields to use for sorting the detail records within the group. If no sort fields are used, then the records appear in their natural order. Sorting the records within the group is the same as adding a Sort Field for a report which was discussed earlier in the chapter. Just open the Record Sort Expert and add the sort field to the Sort Fields list.

It’s important to understand the differences between fields that are sorted within a group and fields that are sorted within a detail section. The Record Sort Expert is strictly used for sorting detail records. It has no control over how the groups are sorted. That said, even though it doesn’t control the group fields, it still shows them in the Sort Fields list. For example, Figure 3-16 shows a report that is grouped by Region and City and the detail records are sorted by Last Name.



Figure 3-16. Record Sort Expert showing groups.

Notice that the first two sort fields are the two grouping fields. After that, it shows the Last Name field. If you click on one of the two grouping fields, all the buttons become disabled because you’re not allowed to change the grouping within this dialog box. If you want to change the group fields, you have to go back to the Group Expert to do so. The reason the group fields are shown here is because Crystal Reports wants to remind you that the group fields always take precedence for sorting and the detail records always come last.