View source
City Project Amount Count
Carthago Army 321.00 $ 0
Army 781.00 $ 4
Army 787.00 $ 0
Arts 985.00 $ 5
Gladiators 991.00 $ 5
Neapolis Arts 9.00 $ 7
Taxes 628.00 $ 7
Taxes 666.00 $ 5
Roma Gladiators 835.00 $ 1
Taxes 232.00 $ 6

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 321.00 $ 0
Army 781.00 $ 4
Army 787.00 $ 0
Arts 985.00 $ 5
Gladiators 991.00 $ 5
Carthago subtotal3865.00 $14
Neapolis Arts 9.00 $ 7
Taxes 628.00 $ 7
Taxes 666.00 $ 5
Neapolis subtotal1303.00 $19
Roma Gladiators 835.00 $ 1
Taxes 232.00 $ 6
Roma subtotal1067.00 $7
Total6235.00 $40

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

Project City Amount Count
Army Carthago 321.00 $ 0
781.00 $ 4
787.00 $ 0
partial amount1889.00 $
Arts Neapolis 9.00 $ 7
Carthago 985.00 $ 5
partial amount994.00 $
Gladiators Roma 835.00 $ 1
Carthago 991.00 $ 5
partial amount1826.00 $
Taxes Roma 232.00 $ 6
Neapolis 628.00 $ 7
666.00 $ 5
partial amount1526.00 $
full total6235.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 321.00 $ 0
Carthago Army 781.00 $ 4
Carthago Army 787.00 $ 0
Carthago Arts 985.00 $ 5
Carthago Gladiators 991.00 $ 5
Neapolis Arts 9.00 $ 7
Neapolis Taxes 628.00 $ 7
Neapolis Taxes 666.00 $ 5
Roma Gladiators 835.00 $ 1
Roma Taxes 232.00 $ 6
6235.00 $40

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
$321.00 0
$781.00 4
$787.00 0
Army Subtotal $1889.00 4
Arts
$985.00 5
Gladiators
$991.00 5
Carthago Subtotal $3865.00 14
Neapolis
Arts
$9.00 7
Taxes
$628.00 7
$666.00 5
Taxes Subtotal $1294.00 12
Neapolis Subtotal $1303.00 19
Roma
Gladiators
$835.00 1
Taxes
$232.00 6
Roma Subtotal $1067.00 7
Total Across All Categories $6235.00 40