### Sorting report data

You can sort the records in a banded object or table, and the groups in a certain group level of the banded object or table if you have defined one or more group levels. If you want the data of other types of cube elements to be sorted, you should put the cube element into a banded object or table and make the data of the cube element inherit from the banded object or table.

- Sorting records: Changing the order of records in the whole banded object or table, or in each group if there exists one or more group levels. The sorting scope is the whole banded object or table.
- Sorting groups in a group level: Changing the order of groups in the group level, that is, the groups will be sorted by the values of the first record in each group on the related field(s). The sorting scope is the group level.

You can achieve the above by using the Sort dialog, shortcut menu, or labels.

#### Using the Sort dialog

To set the sort conditions in the Sort dialog:

1. Click Menu > Report > Sort (or the Sort button on the Analysis toolbar) to bring up the Sort dialog. See the dialog.

2. From the Sort in Scope drop-down list, select a banded object/table or a group field on which the sort condition will be based.
3. From the field drop-down list, select the name of the field on which to sort the data. Set the sort order to Ascending or Descending.
4. If you select a banded object/table in Step 2, you can click to add a new row of sorting condition if required, click or to move a row up or down so as to set the sorting priority, and click To delete the corresponding sorting condition.

   If what you select in the Sort in Scope drop-down list is a group field, then only one sort condition can be composed.

   To retrieve the opening status of this dialog, click the Reset button.

5. Click OK to accept the settings and to reload the result.

#### Using the shortcut menu

To sort data on a certain field using shortcut menu:

1. Point to any value of a detail field or group field by which to sort the data in the banded object/table, and then right-click.
2. Choose the command Sort > Ascending or Sort > Descending from the shortcut menu.

   If what you right-click in Step 1 is a detail field value, the sorting will affect the order of detail records in the banded object or table; if it is a group field value, the order of groups in the group level represented by the group field will be rearranged.

To remove the sort condition on a field, click Sort > No Sort.

#### Using labels

You can use a label to control the sorting order for a certain field. This feature needs to be enabled at report design time.

1. In JReport Designer, select a label in a banded object/table, and then set the Sortable property of the label to true.
2. Set the field by which you want to sort records as the value of the label's Bind Column property.
3. Save the report set and publish it to JReport Enterprise Server.
4. Run the report set in JReport Web, and you can click beside the label to sort the data. This button will change after you have clicked it, and you can further click it to switch the sorting direction among ascending, descending, and no sort.

Notes:

- You cannot sort the data by a global type formula.
- You can also conduct sorting by using the shortcut menu for a label in the same way as for a field value, provided you have set its Bind Column property.
- For sorting the data using shortcut menu or labels, you may notice that the corresponding sort expressions will appear in the Sort dialog if you open this dialog.
- If you use the shortcut menu to sort the report data by a field and then sort by another field, the later sort condition will replace the former one.
- JReport allows you to define display names for fields to be showed in the Sort dialog. For detailed information, see Customizing the field display names in the JReport Designer User's Guide.
- You can right-click an object in a banded object to show a shortcut menu, and then select the Reset item to reproduce the data of the banded object using the data cached in the data buffer. This will clear all sort and filter conditions except for those predefined in JReport Designer.
- Administrators can customize the buffer size for sorting of each report in the Configuration page of JReport Enterprise Server so as to improve performance.