View source
City Project Amount Count
Carthago Arts 50.00 $ 1
Taxes 384.00 $ 0
Taxes 974.00 $ 7
Neapolis Gladiators 747.00 $ 8
Olympia Army 256.00 $ 9
Arts 506.00 $ 1
Arts 782.00 $ 2
Roma Army 584.00 $ 4
Gladiators 985.00 $ 5
Taxes 812.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 Arts 50.00 $ 1
Taxes 384.00 $ 0
Taxes 974.00 $ 7
Carthago subtotal1408.00 $8
Neapolis Gladiators 747.00 $ 8
Neapolis subtotal747.00 $8
Olympia Army 256.00 $ 9
Arts 506.00 $ 1
Arts 782.00 $ 2
Olympia subtotal1544.00 $12
Roma Army 584.00 $ 4
Gladiators 985.00 $ 5
Taxes 812.00 $ 4
Roma subtotal2381.00 $13
Total6080.00 $41

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

Project City Amount Count
Army Olympia 256.00 $ 9
Roma 584.00 $ 4
partial amount840.00 $
Arts Carthago 50.00 $ 1
Olympia 506.00 $ 1
782.00 $ 2
partial amount1338.00 $
Gladiators Neapolis 747.00 $ 8
Roma 985.00 $ 5
partial amount1732.00 $
Taxes Carthago 384.00 $ 0
Roma 812.00 $ 4
Carthago 974.00 $ 7
partial amount2170.00 $
full total6080.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Arts 50.00 $ 1
Carthago Taxes 384.00 $ 0
Carthago Taxes 974.00 $ 7
Neapolis Gladiators 747.00 $ 8
Olympia Army 256.00 $ 9
Olympia Arts 506.00 $ 1
Olympia Arts 782.00 $ 2
Roma Army 584.00 $ 4
Roma Gladiators 985.00 $ 5
Roma Taxes 812.00 $ 4
6080.00 $41

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
Arts
$50.00 1
Taxes
$384.00 0
$974.00 7
Taxes Subtotal $1358.00 7
Carthago Subtotal $1408.00 8
Neapolis
Gladiators
$747.00 8
Olympia
Army
$256.00 9
Arts
$506.00 1
$782.00 2
Arts Subtotal $1288.00 3
Olympia Subtotal $1544.00 12
Roma
Army
$584.00 4
Gladiators
$985.00 5
Taxes
$812.00 4
Roma Subtotal $2381.00 13
Total Across All Categories $6080.00 41