BackPrevious Page Next PageNext

Grouping the Data in Tables

Adding groups in a table

Setting the sort manner of the groups

Specifying Select N conditions for the groups

Applying special functions for the groups

Filtering 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.

Adding groups in a table

  1. When creating or editing a table with the table wizard, click the Group screen (for a summary table in a web report and library component, the Columns screen).

    For a table in a page report, you can also click Insert > Group to add groups in the table.

    Below is a sample UI.

    Create Table wizard - Group

  2. Specify the position of the new group by selecting Table or an existing group in the right box, then:
  3. In the Sort column, set the sort manner of groups at this group level.
  4. Specify the Select N condition for groups at this group level.
  5. If the table is created using a query resource in a page report, you can also specify the following:
  6. Repeat the above steps to add more groups. To adjust the group levels, select a group and click Move Up button or Move Down button. To remove a group, select it and click Remove button or drag and drop it to the Resources box.
  7. Click Finish to apply the settings.

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.

Setting the sort manner of the groups

After a group is added in a table, you need to specify in which manner groups at the group level will be sorted.

Sort Manner List

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.

User Defined Group dialog

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.

Custom Sort

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.

Initial Table

Now you want to sort the groups based on the hire date information. You can specify the sort manner as follows:

  1. Right-click the table and select Table Wizard from the shortcut menu.
  2. In the Group screen of the Table Wizard, select Custom Sort from the drop-down list in the Sort column for the group-by field Assigned Region.
  3. In the Custom Sort dialog, add the field Hire Date as the sort-by field for the group, set the sort order as Ascend, then click OK.

    Select Sort-by Field

  4. Click Finish in the Table Wizard to apply the settings.
  5. Click the View tab to preview the table. You can find that the groups are sorted based on their first record's Hire Date values.

    Preview the Table

Specifying Select N conditions for the groups

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.

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.

  1. Right-click the table and select Table Wizard from the shortcut menu.
  2. In the Group screen of the Table Wizard, select the Table node in the right box, and then click the Select N button.
  3. In the Select N dialog, select Top N from the Select N drop-down list and enter 2 in the combo box.

    Specify Select N Condition on Table

  4. Click OK to go back to the Table Wizard.
  5. Select the group-by field Assigned Region and click the Select N button again.
  6. In the Select N dialog, select Top N , enter 2, check the Other box and enter Others in the text box.
  7. Click OK to close the Select N dialog, then click Finish in the Table Wizard to accept all settings.
  8. Preview the table again. You can find that the first 2 records in each group (the group Latin America has only one record) have been retrieved, and then the first 2 groups (Latin America and Europe, Middle East, Africa) are displayed, with the records in the rest group combined into an additional Others group.

    View table based on query

Applying special functions for the groups

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.

Customized Function

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.

Filtering the groups

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.

Initial Table

Example 1: Showing groups where the lowest employee salary is less than 50000

  1. Right-click the table and select Table Wizard from the shortcut menu.
  2. In the Group screen of the Table Wizard, select the group-by field Employee Position, the Group Filter button is then activated. Click it to display the Group Filter dialog.
  3. Fill in the following information in the dialog:
    Logic Function Field Name (before Occurs With) Field Name (after Occurs With) Operator Value More
    Unchecked Min Salary Salary < 50000 End

    Define Group Filter Condition

  4. Click OK to close the dialog and then Finish in the Table Wizard to apply the settings.
  5. Click the View tab to preview the tab. You can find that only the two groups Marketing and Sales Representative are displayed, while the group Vice President that does not fit this condition is ignored.

    Group Filter Result

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.

Group Filter Result

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.

View report

Notes:

BackPrevious Page Next PageNext