View source
City Project Amount Count
Carthago Army 67.00 $ 7
Gladiators 311.00 $ 6
Taxes 413.00 $ 7
Neapolis Army 890.00 $ 1
Arts 437.00 $ 4
Taxes 96.00 $ 3
Taxes 966.00 $ 8
Olympia Army 959.00 $ 7
Roma Army 486.00 $ 6
Taxes 923.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 67.00 $ 7
Gladiators 311.00 $ 6
Taxes 413.00 $ 7
Carthago subtotal791.00 $20
Neapolis Army 890.00 $ 1
Arts 437.00 $ 4
Taxes 96.00 $ 3
Taxes 966.00 $ 8
Neapolis subtotal2389.00 $16
Olympia Army 959.00 $ 7
Olympia subtotal959.00 $7
Roma Army 486.00 $ 6
Taxes 923.00 $ 0
Roma subtotal1409.00 $6
Total5548.00 $49

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

Project City Amount Count
Army Carthago 67.00 $ 7
Roma 486.00 $ 6
Neapolis 890.00 $ 1
Olympia 959.00 $ 7
partial amount2402.00 $
Arts Neapolis 437.00 $ 4
partial amount437.00 $
Gladiators Carthago 311.00 $ 6
partial amount311.00 $
Taxes Neapolis 96.00 $ 3
Carthago 413.00 $ 7
Roma 923.00 $ 0
Neapolis 966.00 $ 8
partial amount2398.00 $
full total5548.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 67.00 $ 7
Carthago Gladiators 311.00 $ 6
Carthago Taxes 413.00 $ 7
Neapolis Army 890.00 $ 1
Neapolis Arts 437.00 $ 4
Neapolis Taxes 96.00 $ 3
Neapolis Taxes 966.00 $ 8
Olympia Army 959.00 $ 7
Roma Army 486.00 $ 6
Roma Taxes 923.00 $ 0
5548.00 $49

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
$67.00 7
Gladiators
$311.00 6
Taxes
$413.00 7
Carthago Subtotal $791.00 20
Neapolis
Army
$890.00 1
Arts
$437.00 4
Taxes
$96.00 3
$966.00 8
Taxes Subtotal $1062.00 11
Neapolis Subtotal $2389.00 16
Olympia
Army
$959.00 7
Roma
Army
$486.00 6
Taxes
$923.00 0
Roma Subtotal $1409.00 6
Total Across All Categories $5548.00 49