View source
City Project Amount Count
Carthago Army 865.00 $ 8
Army 983.00 $ 2
Neapolis Gladiators 628.00 $ 3
Taxes 823.00 $ 1
Olympia Army 117.00 $ 6
Taxes 359.00 $ 4
Roma Army 6.00 $ 8
Gladiators 672.00 $ 2
Gladiators 924.00 $ 7
Taxes 128.00 $ 2

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 865.00 $ 8
Army 983.00 $ 2
Carthago subtotal1848.00 $10
Neapolis Gladiators 628.00 $ 3
Taxes 823.00 $ 1
Neapolis subtotal1451.00 $4
Olympia Army 117.00 $ 6
Taxes 359.00 $ 4
Olympia subtotal476.00 $10
Roma Army 6.00 $ 8
Gladiators 672.00 $ 2
Gladiators 924.00 $ 7
Taxes 128.00 $ 2
Roma subtotal1730.00 $19
Total5505.00 $43

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

Project City Amount Count
Army Roma 6.00 $ 8
Olympia 117.00 $ 6
Carthago 865.00 $ 8
983.00 $ 2
partial amount1971.00 $
Gladiators Neapolis 628.00 $ 3
Roma 672.00 $ 2
924.00 $ 7
partial amount2224.00 $
Taxes Roma 128.00 $ 2
Olympia 359.00 $ 4
Neapolis 823.00 $ 1
partial amount1310.00 $
full total5505.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 865.00 $ 8
Carthago Army 983.00 $ 2
Neapolis Gladiators 628.00 $ 3
Neapolis Taxes 823.00 $ 1
Olympia Army 117.00 $ 6
Olympia Taxes 359.00 $ 4
Roma Army 6.00 $ 8
Roma Gladiators 672.00 $ 2
Roma Gladiators 924.00 $ 7
Roma Taxes 128.00 $ 2
5505.00 $43

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
$865.00 8
$983.00 2
Army Subtotal $1848.00 10
Carthago Subtotal $1848.00 10
Neapolis
Gladiators
$628.00 3
Taxes
$823.00 1
Neapolis Subtotal $1451.00 4
Olympia
Army
$117.00 6
Taxes
$359.00 4
Olympia Subtotal $476.00 10
Roma
Army
$6.00 8
Gladiators
$672.00 2
$924.00 7
Gladiators Subtotal $1596.00 9
Taxes
$128.00 2
Roma Subtotal $1730.00 19
Total Across All Categories $5505.00 43