View source
City Project Amount Count
Carthago Arts 18.00 $ 1
Neapolis Army 561.00 $ 4
Arts 608.00 $ 2
Taxes 135.00 $ 6
Roma Army 49.00 $ 2
Army 651.00 $ 5
Arts 484.00 $ 5
Gladiators 775.00 $ 5
Gladiators 954.00 $ 1
Taxes 464.00 $ 5

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 Arts 18.00 $ 1
Carthago subtotal18.00 $1
Neapolis Army 561.00 $ 4
Arts 608.00 $ 2
Taxes 135.00 $ 6
Neapolis subtotal1304.00 $12
Roma Army 49.00 $ 2
Army 651.00 $ 5
Arts 484.00 $ 5
Gladiators 775.00 $ 5
Gladiators 954.00 $ 1
Taxes 464.00 $ 5
Roma subtotal3377.00 $23
Total4699.00 $36

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

Project City Amount Count
Army Roma 49.00 $ 2
Neapolis 561.00 $ 4
Roma 651.00 $ 5
partial amount1261.00 $
Arts Carthago 18.00 $ 1
Roma 484.00 $ 5
Neapolis 608.00 $ 2
partial amount1110.00 $
Gladiators Roma 775.00 $ 5
954.00 $ 1
partial amount1729.00 $
Taxes Neapolis 135.00 $ 6
Roma 464.00 $ 5
partial amount599.00 $
full total4699.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Arts 18.00 $ 1
Neapolis Army 561.00 $ 4
Neapolis Arts 608.00 $ 2
Neapolis Taxes 135.00 $ 6
Roma Army 49.00 $ 2
Roma Army 651.00 $ 5
Roma Arts 484.00 $ 5
Roma Gladiators 775.00 $ 5
Roma Gladiators 954.00 $ 1
Roma Taxes 464.00 $ 5
4699.00 $36

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
Arts
$18.00 1
Neapolis
Army
$561.00 4
Arts
$608.00 2
Taxes
$135.00 6
Neapolis Subtotal $1304.00 12
Roma
Army
$49.00 2
$651.00 5
Army Subtotal $700.00 7
Arts
$484.00 5
Gladiators
$775.00 5
$954.00 1
Gladiators Subtotal $1729.00 6
Taxes
$464.00 5
Roma Subtotal $3377.00 23
Total Across All Categories $4699.00 36