Groups and totals

Top  Previous  Next

Earlier we looked at the "Master-detail" report type, which printed data from two related sources. FastReport allows creating a report which looks in the same way, but uses one data source. For this, groups are used.

 

A group is a set of three bands: "Group header", "Data" and "Group footer". In designer, this looks as follows:

 

group3

 

A group always contains a header and data. Group footer is optional, you can delete it.

 

In order to use a group, you should set the group condition for the group header, and connect the data source to the "Data" band. The condition can be any expression, but as a rule, this is one of the data source columns. Group printing is done in the following way:

 

1.group header is printed.
2.data row is printed.
3.checks if the grouping condition has changed.
4.if the condition has not changed, next data row is printed (p.2).
5.if the condition has changed, the group footer is printed, and starts printing a new group (p.1).

 

Assuming that we have a Products table with the following data:

 

group1

 

Data can be grouped on the CategoryName column. This column will be printed in the group header. The data itself is presented by the ProductName field. The report will be as follows:

 

group4

 

If we run the report, the following will be seen:

 

group2