Setting the sort manner of the groups
Specifying Select N conditions for the groups
Data in a table is usually organized into groups based on certain criteria. You can define multi-level groups in your table either when creating it or after the table is generated.
For a table in a page report, you can also click Insert > Group to add groups in the table.
Below is a sample UI.
One or more GH-GF (group header and group footer) row pairs with the selected group-by fields are now displayed in the table.
You can also add groups to a table by means of inserting group columns in the table.
Note: The following SQL type of data cannot be grouped: Db.SQL_BINARY, Db.SQL_BLOB, Db.SQL_CLOB, Db.SQL_LONGVARCHAR, Db.SQL_LONGVARBINARY, Db.SQL_VARBINARY and Db.SQL_OTHER.
After a group is added in a table, you need to specify in which manner groups at the group level will be sorted.
Ascend
Groups will be sorted in ascending order.
Descend
Groups will be sorted in descending order.
No Sort
Groups will be arranged in their original order.
Special Group
Selecting this item will bring out the User Defined Group dialog for you to define how to group your information. This option is only available for tables created using query resources.
For example, if you place a field named Score for grouping which contains student scores that range from 0 to 100, and you want to group the students in 5 ranks, namely rank A: 90~100, B: 80~89, C: 70~79, D: 60~69, and E: 0~59. You can set the following with the User Defined Group dialog.
Group Name | Operator | Operand |
---|---|---|
A | between | Op1: 90, Op2: 100 |
B | between | Op1: 80, Op2: 89 |
C | between | Op1: 70, Op2: 79 |
D | between | Op2: 60, Op2: 69 |
F | <= | 59 |
There will be five groups in the order from A to F. If you want to change the order of the groups, you can also do so via the User Defined Group dialog.
Selecting this item will bring out the Custom Sort dialog for you to define how to sort the groups at current group level. You can specify some fields in the dialog as the sort-by fields, then the groups will be sorted by the values of the first record in each group on the related fields.
The following example shows how to sort groups by a specific field.
Suppose that you have created a table of Group Above type in a page report in the catalog SampleReports.cat saved in <install_root>\Demo\Reports\SampleReports
. The table uses the query EmployeeInformation in Data Source 1 of the catalog, displays Name, Hire Date, Employee Position and Notes, is grouped by Assigned Region in Descend order, and applies the JReportDemo style.
Now you want to sort the groups based on the hire date information. You can specify the sort manner as follows:
Sometimes, you may want to show data from a range in a group or some groups in a table. To achieve this, you can use the Select N feature. By specifying a Select N condition, you can decide how many records or groups will be displayed in the table. You can also use an Integer-typed parameter to control the value of Select N.
By default, All is selected, which means that all records will be displayed.
If you select Top N or Bottom N, then you can further specify a number in the combo box below. You can also use an Integer-typed parameter in the current catalog to define the Top/Bottom N condition dynamically. Supposing the number or the value you will specify for the parameter is N, when you view the result, you will find that only the first or last N records in the whole table or in each group (if any group has been defined) are retrieved.
Notes:
Example: Applying Select N conditions in a table
Based on the table result in the above example, we will set two Select N conditions in the table, one for the whole table and the other for the groups in the table.
If a group-by field is of Numeric, String or Date/Time type in a table, you can select a special function for it in the Special Function column. This is called "grouping data by intervals" in JReport. It enables you to group data more clearly and logically, and to summarize data more effectively. However this feature is supported in page reports created using query resources only.
The following is a short description of each special function.
Special functions for Numeric type
Function | Description |
---|---|
None | All the records that have the same field value will be displayed together as a group. |
Up to 5 | The records will be grouped by intervals of 5. |
Up to 10 | The records will be grouped by intervals of 10. |
Up to 50 | The records will be grouped by intervals of 50. |
Up to 100 | The records will be grouped by intervals of 100. |
Up to 500 | The records will be grouped by intervals of 500. |
Up to 1000 | The records will be grouped by intervals of 1000. |
Up to 5000 | The records will be grouped by intervals of 5000. |
Up to 10000 | The records will be grouped by intervals of 10000. |
Special functions for String type
Function | Description |
---|---|
None | All the records that have the same field value will be displayed together as a group. |
For 1st letter | The records, of which the field values' first letter is the same, will be grouped together. |
For first 2 letters | The records, of which the field values' first two letters are the same, will be grouped together. |
For first 3 letters | The records, of which the field values' first three letters are the same, will be grouped together. |
For first 4 letters | The records, of which the field values' first four letters are the same, will be grouped together. |
For first 5 letters | The records, of which the field values' first five letters are the same, will be grouped together. |
For last 1 letter | The records, of which the field values' last letter is the same, will be grouped together. |
For last 2 letters | The records, of which the field values' last two letters are the same, will be grouped together. |
For last 3 letters | The records, of which the field values' last three letters are the same, will be grouped together. |
For last 4 letters | The records, of which the field values' last four letters are the same, will be grouped together. |
For last 5 letters | The records, of which the field values' last five letters are the same, will be grouped together. |
Special functions for Date/Time type
Function | Description |
---|---|
None | All the records that have the same field value will be displayed together as a group. |
For each second | The records, of which the field values are in the same second, will be grouped together. |
For each minute | The records, of which the field values are in the same minute, will be grouped together. |
For each hour | The records, of which the field values are in the same hour, will be grouped together. |
For each day | The records, of which the field values are in the same day, will be grouped together. |
For each week | The records, of which the field values are in the same week, will be grouped together. |
For each bi-week | The records, of which the field values are in the same bi-week, will be grouped together. |
For each half month | The records, of which the field values are in the same half month, will be grouped together. |
For each month | The records, of which the field values are in the same month, will be grouped together. |
For each quarter | The records, of which the field values are in the same quarter, will be grouped together. |
For each half year | The records, of which the field values are in the same half year, will be grouped together. |
For each year | The records, of which the field values are in the same year, will be grouped together. |
In the special function list for all the above data types, there is an item called Customize. By selecting this item, you can define a special function by yourself.
If you want to group the data by intervals, check the By Intervals radio button, then define the interval in the Numerical Value text box.
If you want to group data by a range, check the Within Range radio button, specify the range in the Within text box and select how to apply the range: apply to increasing data or decreasing data.
Note: When grouping Numeric typed data by intervals, JReport follows this rule: all values in each range are >= the minimum value in the range and < the maximum value in the range, and 0 is the offset for the intervals.
For example, if you specify to group the following values by intervals of 5: -8, -6, -5, -3, -1, 0, 1, 3, 4, 5, 8, the results will be as follows:
Ranges | Values |
---|---|
-10 to -5 | -8, -6 |
-5 to 0 | -5, -3, -1 |
0 to 5 | 0, 1, 3, 4 |
5 to 10 | 5, 8 |
For example, to group records by the first N letters of the group-by field values, select First from the drop-down list and then enter N in the text box. Note that the number of letters should be an integer no larger than 255.
Note: If you check Case sensitive when grouping, No Conversion will be checked as the default converting method.
By default, JReport takes 1/1/1970 00:00:00 as the offset. If you want to define the offset by yourself, check the Customized Value radio button and then click the calendar button to choose the required offset.
By applying a filter condition to the groups in table, you can specify the groups to display in the table: if a group satisfies the filter condition, all the records in this group will be shown; if a group doesn't satisfy the condition, then the whole group will not be displayed in the table.
The Group Filter feature is supported in page reports created using query resources only.
Suppose that you have created a table of Group Above type in a page report in the catalog SampleReports.cat saved in <install_root>\Demo\Reports\SampleReports
. The table uses the query EmployeeInformation in Data Source 1 of the catalog, displays Name, Hire Date, Home Phone and Salary, is grouped by Employee Position in Ascend order, and applies the JReportDemo style. Since no group filter condition has been set, there are three groups in the table: Marketing, Sales Representative and Vice President.
Example 1: Showing groups where the lowest employee salary is less than 50000
Logic | Function | Field Name (before Occurs With) | Field Name (after Occurs With) | Operator | Value | More |
---|---|---|---|---|---|---|
Unchecked | Min | Salary | Salary | < | 50000 | End |
Example 2: Showing groups in which the highest-salary employee was hired before Jan. 1, 1989
In this example, you need to set the Group Filter dialog as follows:
Logic | Function | Field Name (before Occurs With) | Field Name (after Occurs With) | Operator | Value | More |
---|---|---|---|---|---|---|
Unchecked | Max | Salary | Hire Date | < | 1989-01-01 00:00:00.000 | End |
When you preview the tab, you will find that this time only the group Vice President is displayed.
Example 3: Showing groups where at least one "not highest" employee salary is larger than or equal to 50000
In this example, you need to set the Group Filter dialog as follows:
Logic | Function | Field Name (before Occurs With) | Field Name (after Occurs With) | Operator | Value | More |
---|---|---|---|---|---|---|
Checked | Max | Salary | Salary | >= | 50000 | End |
When you view the report result, you will find that this time only the two groups Sales Representative and Vice President are displayed.
Notes: