View source
City Project Amount Count
Carthago Gladiators 142.00 $ 0
Taxes 466.00 $ 5
Neapolis Army 223.00 $ 6
Army 854.00 $ 1
Olympia Gladiators 319.00 $ 6
Taxes 468.00 $ 1
Roma Army 180.00 $ 8
Arts 290.00 $ 2
Arts 669.00 $ 4
Arts 679.00 $ 4

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 Gladiators 142.00 $ 0
Taxes 466.00 $ 5
Carthago subtotal608.00 $5
Neapolis Army 223.00 $ 6
Army 854.00 $ 1
Neapolis subtotal1077.00 $7
Olympia Gladiators 319.00 $ 6
Taxes 468.00 $ 1
Olympia subtotal787.00 $7
Roma Army 180.00 $ 8
Arts 290.00 $ 2
Arts 669.00 $ 4
Arts 679.00 $ 4
Roma subtotal1818.00 $18
Total4290.00 $37

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

Project City Amount Count
Army Roma 180.00 $ 8
Neapolis 223.00 $ 6
854.00 $ 1
partial amount1257.00 $
Arts Roma 290.00 $ 2
669.00 $ 4
679.00 $ 4
partial amount1638.00 $
Gladiators Carthago 142.00 $ 0
Olympia 319.00 $ 6
partial amount461.00 $
Taxes Carthago 466.00 $ 5
Olympia 468.00 $ 1
partial amount934.00 $
full total4290.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Gladiators 142.00 $ 0
Carthago Taxes 466.00 $ 5
Neapolis Army 223.00 $ 6
Neapolis Army 854.00 $ 1
Olympia Gladiators 319.00 $ 6
Olympia Taxes 468.00 $ 1
Roma Army 180.00 $ 8
Roma Arts 290.00 $ 2
Roma Arts 669.00 $ 4
Roma Arts 679.00 $ 4
4290.00 $37

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
Gladiators
$142.00 0
Taxes
$466.00 5
Carthago Subtotal $608.00 5
Neapolis
Army
$223.00 6
$854.00 1
Army Subtotal $1077.00 7
Neapolis Subtotal $1077.00 7
Olympia
Gladiators
$319.00 6
Taxes
$468.00 1
Olympia Subtotal $787.00 7
Roma
Army
$180.00 8
Arts
$290.00 2
$669.00 4
$679.00 4
Arts Subtotal $1638.00 10
Roma Subtotal $1818.00 18
Total Across All Categories $4290.00 37