View source
City Project Amount Count
Carthago Army 325.00 $ 9
Army 574.00 $ 4
Olympia Taxes 73.00 $ 0
Taxes 659.00 $ 2
Roma Army 649.00 $ 1
Arts 941.00 $ 7
Taxes 157.00 $ 2
Taxes 266.00 $ 4
Taxes 849.00 $ 9
Taxes 894.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 325.00 $ 9
Army 574.00 $ 4
Carthago subtotal899.00 $13
Olympia Taxes 73.00 $ 0
Taxes 659.00 $ 2
Olympia subtotal732.00 $2
Roma Army 649.00 $ 1
Arts 941.00 $ 7
Taxes 157.00 $ 2
Taxes 266.00 $ 4
Taxes 849.00 $ 9
Taxes 894.00 $ 0
Roma subtotal3756.00 $23
Total5387.00 $38

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

Project City Amount Count
Army Carthago 325.00 $ 9
574.00 $ 4
Roma 649.00 $ 1
partial amount1548.00 $
Arts Roma 941.00 $ 7
partial amount941.00 $
Taxes Olympia 73.00 $ 0
Roma 157.00 $ 2
266.00 $ 4
Olympia 659.00 $ 2
Roma 849.00 $ 9
894.00 $ 0
partial amount2898.00 $
full total5387.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 325.00 $ 9
Carthago Army 574.00 $ 4
Olympia Taxes 73.00 $ 0
Olympia Taxes 659.00 $ 2
Roma Army 649.00 $ 1
Roma Arts 941.00 $ 7
Roma Taxes 157.00 $ 2
Roma Taxes 266.00 $ 4
Roma Taxes 849.00 $ 9
Roma Taxes 894.00 $ 0
5387.00 $38

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
$325.00 9
$574.00 4
Army Subtotal $899.00 13
Carthago Subtotal $899.00 13
Olympia
Taxes
$73.00 0
$659.00 2
Taxes Subtotal $732.00 2
Olympia Subtotal $732.00 2
Roma
Army
$649.00 1
Arts
$941.00 7
Taxes
$157.00 2
$266.00 4
$849.00 9
$894.00 0
Taxes Subtotal $2166.00 15
Roma Subtotal $3756.00 23
Total Across All Categories $5387.00 38