View source
City Project Amount Count
Carthago Army 649.00 $ 5
Gladiators 379.00 $ 6
Taxes 318.00 $ 6
Olympia Army 35.00 $ 5
Army 756.00 $ 4
Arts 146.00 $ 5
Arts 222.00 $ 7
Gladiators 595.00 $ 9
Roma Arts 258.00 $ 8
Arts 524.00 $ 9

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 649.00 $ 5
Gladiators 379.00 $ 6
Taxes 318.00 $ 6
Carthago subtotal1346.00 $17
Olympia Army 35.00 $ 5
Army 756.00 $ 4
Arts 146.00 $ 5
Arts 222.00 $ 7
Gladiators 595.00 $ 9
Olympia subtotal1754.00 $30
Roma Arts 258.00 $ 8
Arts 524.00 $ 9
Roma subtotal782.00 $17
Total3882.00 $64

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

Project City Amount Count
Army Olympia 35.00 $ 5
Carthago 649.00 $ 5
Olympia 756.00 $ 4
partial amount1440.00 $
Arts Olympia 146.00 $ 5
222.00 $ 7
Roma 258.00 $ 8
524.00 $ 9
partial amount1150.00 $
Gladiators Carthago 379.00 $ 6
Olympia 595.00 $ 9
partial amount974.00 $
Taxes Carthago 318.00 $ 6
partial amount318.00 $
full total3882.00 $

Totals for amount and count, without groups.

City Project Amount Count
Carthago Army 649.00 $ 5
Carthago Gladiators 379.00 $ 6
Carthago Taxes 318.00 $ 6
Olympia Army 35.00 $ 5
Olympia Army 756.00 $ 4
Olympia Arts 146.00 $ 5
Olympia Arts 222.00 $ 7
Olympia Gladiators 595.00 $ 9
Roma Arts 258.00 $ 8
Roma Arts 524.00 $ 9
3882.00 $64

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
$649.00 5
Gladiators
$379.00 6
Taxes
$318.00 6
Carthago Subtotal $1346.00 17
Olympia
Army
$35.00 5
$756.00 4
Army Subtotal $791.00 9
Arts
$146.00 5
$222.00 7
Arts Subtotal $368.00 12
Gladiators
$595.00 9
Olympia Subtotal $1754.00 30
Roma
Arts
$258.00 8
$524.00 9
Arts Subtotal $782.00 17
Roma Subtotal $782.00 17
Total Across All Categories $3882.00 64