Grouping rows

You can group related rows together and, optionally, calculate statistics for each group separately. For example, you might want to group employee information by department and get total salaries for each department.

How groups are defined

Each group is defined by one or more DataWindow object columns. Each time the value in a grouping column changes, a break occurs and a new section begins.

For each group you can:

Grouping example

The following DataWindow object retrieves employee information. It has one group defined, Dept_ID, so it groups rows into sections according to the value in the Dept_ID column. In addition, it displays:

Figure 22-5 shows the DataWindow object. Grouping the data has the effect of suppressing repeated values for the column or columns on which the grouping is based.

Figure 22-5: Last page of report for employees grouped by department

The sample is titled Employee Report. Data for employee I D and Salary is grouped by department I D.  At the end of the row for the data for department 500 is a total for the salaries of department employees. A Grand Total for the salaries of all departments displays below that.

How to do it

You can create a grouped DataWindow object in two ways:

Making the DataWindow control large enough

If a DataWindow object has grouped rows, each page contains all group headers (including zero-height headers) at the top of the page.

The last row of a group displays on the same page as that row's group trailer and each applicable higher level group trailer. If the DataWindow object has a summary band, it displays on the same page as the last row of the report. If the control is not large enough, you might see anomalies when scrolling through the DataWindow object. This is particularly likely in the last row of the report, which needs room to display the report's header band, all group headers, all group trailers, the summary band, and the footer band.

If you cannot increase the height of the DataWindow control so that it has room for all the headers and trailers, you can change the design of the DataWindow object so that they require less space.

Scrolling through a grouped DataWindow

When you scroll through a grouped DataWindow object, you might see the group header repeated where you do not expect it. This is because the data is paginated in a fixed layout based on the size of the DataWindow control. You can scroll to a point that shows the bottom half of one page and the top of the next.

When you use the arrow keys to page through the data, you see the data one page at a time, but you (or your application users) might have to press the arrow keys several times before the next page is displayed. The SIP keyboard or a peripheral keyboard can be used to scroll through DataWindow pages deployed to a PDA device.