View source
City Project Amount Count
Carthago Army 317.00 $ 1
Army 668.00 $ 2
Arts 967.00 $ 4
Gladiators 218.00 $ 6
Olympia Army 418.00 $ 5
Army 552.00 $ 3
Arts 13.00 $ 9
Arts 588.00 $ 1
Roma Army 332.00 $ 6
Army 558.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 317.00 $ 1
Army 668.00 $ 2
Arts 967.00 $ 4
Gladiators 218.00 $ 6
Carthago subtotal2170.00 $13
Olympia Army 418.00 $ 5
Army 552.00 $ 3
Arts 13.00 $ 9
Arts 588.00 $ 1
Olympia subtotal1571.00 $18
Roma Army 332.00 $ 6
Army 558.00 $ 6
Roma subtotal890.00 $12
Total4631.00 $43

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

Project City Amount Count
Army Carthago 317.00 $ 1
Roma 332.00 $ 6
Olympia 418.00 $ 5
552.00 $ 3
Roma 558.00 $ 6
Carthago 668.00 $ 2
partial amount2845.00 $
Arts Olympia 13.00 $ 9
588.00 $ 1
Carthago 967.00 $ 4
partial amount1568.00 $
Gladiators Carthago 218.00 $ 6
partial amount218.00 $
full total4631.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 317.00 $ 1
Carthago Army 668.00 $ 2
Carthago Arts 967.00 $ 4
Carthago Gladiators 218.00 $ 6
Olympia Army 418.00 $ 5
Olympia Army 552.00 $ 3
Olympia Arts 13.00 $ 9
Olympia Arts 588.00 $ 1
Roma Army 332.00 $ 6
Roma Army 558.00 $ 6
4631.00 $43

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
$317.00 1
$668.00 2
Army Subtotal $985.00 3
Arts
$967.00 4
Gladiators
$218.00 6
Carthago Subtotal $2170.00 13
Olympia
Army
$418.00 5
$552.00 3
Army Subtotal $970.00 8
Arts
$13.00 9
$588.00 1
Arts Subtotal $601.00 10
Olympia Subtotal $1571.00 18
Roma
Army
$332.00 6
$558.00 6
Army Subtotal $890.00 12
Roma Subtotal $890.00 12
Total Across All Categories $4631.00 43