Sorting the Data
By default, the records in a table are displayed randomly; they are displayed in the order they are returned from the fetch operation. You can specify that Logi JReport sort the records in a table, and also within the groups in the table, if any.
The following example shows how to set the sorting criteria in a table.
Suppose that you have created a table based on the query EmployeeInformation in the catalog file SampleReports.cat saved in <install_root>\Demo\Reports\SampleReports
as follows: added the fields Hire Date, Name, Home Phone and Salary to be displayed in the table, set the field Employee Position as the group by field and Ascend as the sort order, then applied the Neutral style to the table.
For the example, specify the sorting criteria as follows:
- Right-click the table and select Table Wizard from the shortcut menu.
- In the Table Wizard, select the Display screen, then select the Sort Fields By button.
- In the Sort Fields By dialog, select the field Hire Date as the sort by field from the Resources box and select or drag and drop it to the sort fields by box on the right, select Ascend from the Sort column, then select OK to accept the changes.
- Select Finish in the Table Wizard to apply the settings.
- View the table again and you will find that the records in each group are displayed in ascending order by Hire Date.
Sorting Data Dynamically
Similar to dynamic grouping, sorting can also be defined at runtime. Using the table in the above example, you can apply a dynamic sort on it as follows:
- Right-click the table and select Table Wizard from the shortcut menu.
- In the Table Wizard, select the Display screen, then select the Sort Fields By button.
- In the Sort Fields By dialog, remove the sort by field Hire Date set in the above example.
- In the Resources box, select <New Parameter...> in the Parameters node.
- In the New Parameter dialog, create a type-in parameter named SortBy of String type (leave the other settings to their default), then select OK.
- Add the just created parameter SortBy as the sort by field.
- Select Dynamic Sort in the sort order drop-down list of the Sort column.
- In the Specify Sort Order for dialog, input SortBy Order, then select OK to close the dialog.
- Select OK in the Sort Fields By dialog to accept the changes.
- Select Finish in the Table Wizard to apply the settings.
- View the report result. In the Enter Parameter Values dialog, select a field from the SortBy drop-down list and specify the sorting manner in the SortBy Order drop-down list.
Here, we choose Salary from the SortBy list and DESCENDING from the SortBy Order list. The records within each group are displayed in descending order according to their salary values.
Note: The following SQL type of data cannot be sorted: Db.SQL_BINARY, Db.SQL_BLOB, Db.SQL_CLOB, Db.SQL_LONGVARCHAR, Db.SQL_LONGVARBINARY, Db.SQL_VARBINARY and Db.SQL_OTHER.