View source
City Project Amount Count
Carthago Army 695.00 $ 5
Army 786.00 $ 5
Army 926.00 $ 5
Gladiators 694.00 $ 9
Taxes 710.00 $ 2
Neapolis Army 506.00 $ 4
Army 589.00 $ 0
Gladiators 147.00 $ 8
Roma Gladiators 235.00 $ 8
Taxes 4.00 $ 0

The table above shows a simple report, grouped by the "city" value, and with some amount.

The following tables are based on the same code, with the only addition of a table decorator org.displaytag.decorator.TotalTableDecorator .

The decorator will generate totals for any column with the total attribute set, and subtotal rows by grouping using the column with a group attribute set to 1.


Group by city, total for amount and count

City Project Amount Count
Carthago Army 695.00 $ 5
Army 786.00 $ 5
Army 926.00 $ 5
Gladiators 694.00 $ 9
Taxes 710.00 $ 2
Carthago subtotal3811.00 $26
Neapolis Army 506.00 $ 4
Army 589.00 $ 0
Gladiators 147.00 $ 8
Neapolis subtotal1242.00 $12
Roma Gladiators 235.00 $ 8
Taxes 4.00 $ 0
Roma subtotal239.00 $8
Total5292.00 $46

Group by project and city, totals for amount only, customize labels.

Project City Amount Count
Army Neapolis 506.00 $ 4
589.00 $ 0
Carthago 695.00 $ 5
786.00 $ 5
926.00 $ 5
partial amount3502.00 $
Gladiators Neapolis 147.00 $ 8
Roma 235.00 $ 8
Carthago 694.00 $ 9
partial amount1076.00 $
Taxes Roma 4.00 $ 0
Carthago 710.00 $ 2
partial amount714.00 $
full total5292.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 695.00 $ 5
Carthago Army 786.00 $ 5
Carthago Army 926.00 $ 5
Carthago Gladiators 694.00 $ 9
Carthago Taxes 710.00 $ 2
Neapolis Army 506.00 $ 4
Neapolis Army 589.00 $ 0
Neapolis Gladiators 147.00 $ 8
Roma Gladiators 235.00 $ 8
Roma Taxes 4.00 $ 0
5292.00 $46

If you need subtotals for subgroups, try the MultilevelTotalTableDecorator. Items with only one entry are not totaled separately, but items that occur more than once are subtotaled together.

City Project Amount Count
Carthago
Army
$695.00 5
$786.00 5
$926.00 5
Army Subtotal $2407.00 15
Gladiators
$694.00 9
Taxes
$710.00 2
Carthago Subtotal $3811.00 26
Neapolis
Army
$506.00 4
$589.00 0
Army Subtotal $1095.00 4
Gladiators
$147.00 8
Neapolis Subtotal $1242.00 12
Roma
Gladiators
$235.00 8
Taxes
$4.00 0
Roma Subtotal $239.00 8
Total Across All Categories $5292.00 46