View source
City Project Amount Count
Carthago Army 490.00 $ 0
Arts 13.00 $ 4
Gladiators 432.00 $ 6
Gladiators 898.00 $ 8
Neapolis Taxes 88.00 $ 3
Olympia Taxes 790.00 $ 8
Roma Army 802.00 $ 9
Arts 477.00 $ 2
Arts 901.00 $ 8
Taxes 891.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 Army 490.00 $ 0
Arts 13.00 $ 4
Gladiators 432.00 $ 6
Gladiators 898.00 $ 8
Carthago subtotal1833.00 $18
Neapolis Taxes 88.00 $ 3
Neapolis subtotal88.00 $3
Olympia Taxes 790.00 $ 8
Olympia subtotal790.00 $8
Roma Army 802.00 $ 9
Arts 477.00 $ 2
Arts 901.00 $ 8
Taxes 891.00 $ 4
Roma subtotal3071.00 $23
Total5782.00 $52

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

Project City Amount Count
Army Carthago 490.00 $ 0
Roma 802.00 $ 9
partial amount1292.00 $
Arts Carthago 13.00 $ 4
Roma 477.00 $ 2
901.00 $ 8
partial amount1391.00 $
Gladiators Carthago 432.00 $ 6
898.00 $ 8
partial amount1330.00 $
Taxes Neapolis 88.00 $ 3
Olympia 790.00 $ 8
Roma 891.00 $ 4
partial amount1769.00 $
full total5782.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 490.00 $ 0
Carthago Arts 13.00 $ 4
Carthago Gladiators 432.00 $ 6
Carthago Gladiators 898.00 $ 8
Neapolis Taxes 88.00 $ 3
Olympia Taxes 790.00 $ 8
Roma Army 802.00 $ 9
Roma Arts 477.00 $ 2
Roma Arts 901.00 $ 8
Roma Taxes 891.00 $ 4
5782.00 $52

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
$490.00 0
Arts
$13.00 4
Gladiators
$432.00 6
$898.00 8
Gladiators Subtotal $1330.00 14
Carthago Subtotal $1833.00 18
Neapolis
Taxes
$88.00 3
Olympia
Taxes
$790.00 8
Roma
Army
$802.00 9
Arts
$477.00 2
$901.00 8
Arts Subtotal $1378.00 10
Taxes
$891.00 4
Roma Subtotal $3071.00 23
Total Across All Categories $5782.00 52