View source
City Project Amount Count
Carthago Army 359.00 $ 9
Arts 80.00 $ 5
Neapolis Army 553.00 $ 1
Arts 395.00 $ 9
Arts 984.00 $ 2
Olympia Arts 711.00 $ 3
Taxes 127.00 $ 5
Roma Arts 828.00 $ 2
Gladiators 270.00 $ 8
Taxes 654.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 359.00 $ 9
Arts 80.00 $ 5
Carthago subtotal439.00 $14
Neapolis Army 553.00 $ 1
Arts 395.00 $ 9
Arts 984.00 $ 2
Neapolis subtotal1932.00 $12
Olympia Arts 711.00 $ 3
Taxes 127.00 $ 5
Olympia subtotal838.00 $8
Roma Arts 828.00 $ 2
Gladiators 270.00 $ 8
Taxes 654.00 $ 0
Roma subtotal1752.00 $10
Total4961.00 $44

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

Project City Amount Count
Army Carthago 359.00 $ 9
Neapolis 553.00 $ 1
partial amount912.00 $
Arts Carthago 80.00 $ 5
Neapolis 395.00 $ 9
Olympia 711.00 $ 3
Roma 828.00 $ 2
Neapolis 984.00 $ 2
partial amount2998.00 $
Gladiators Roma 270.00 $ 8
partial amount270.00 $
Taxes Olympia 127.00 $ 5
Roma 654.00 $ 0
partial amount781.00 $
full total4961.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 359.00 $ 9
Carthago Arts 80.00 $ 5
Neapolis Army 553.00 $ 1
Neapolis Arts 395.00 $ 9
Neapolis Arts 984.00 $ 2
Olympia Arts 711.00 $ 3
Olympia Taxes 127.00 $ 5
Roma Arts 828.00 $ 2
Roma Gladiators 270.00 $ 8
Roma Taxes 654.00 $ 0
4961.00 $44

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
$359.00 9
Arts
$80.00 5
Carthago Subtotal $439.00 14
Neapolis
Army
$553.00 1
Arts
$395.00 9
$984.00 2
Arts Subtotal $1379.00 11
Neapolis Subtotal $1932.00 12
Olympia
Arts
$711.00 3
Taxes
$127.00 5
Olympia Subtotal $838.00 8
Roma
Arts
$828.00 2
Gladiators
$270.00 8
Taxes
$654.00 0
Roma Subtotal $1752.00 10
Total Across All Categories $4961.00 44