Preciso Sensedge
Preciso Sensedge

Reputation: 35

How to display sum of each columns at footer in JasperReports without groups using DynamicJasper?

I tried using the method below.

drb.addGlobalFooterVariable(totalAmount, DJCalculation.SUM);
drb.addGlobalFooterVariable(basicAmount, DJCalculation.SUM);

But it shows me the value of last row (of each column) instead of the sum of each column in the footer (as shown in images).

Do I miss something?

enter image description here

Upvotes: 2

Views: 1528

Answers (2)

Benson Kiprono
Benson Kiprono

Reputation: 129

Hello? This question might be old but I will answer it for the sake of future viewers. I experienced the same problem in dynamic jasper. I had set my column property to string instead of double. changing it to double solved the issue and the totals are now okay. This is what I had

            AbstractColumn ENGLISH = ColumnBuilder.getNew()
                .setColumnProperty("TOTAL%", String.class.getName())
                .setTitle("ENG").setWidth(new Integer(80))
                .setStyle(detailStyle1).setHeaderStyle(headerStyle)
                .build();

So i changed this

.setColumnProperty("TOTAL%", String.class.getName())

to this

.setColumnProperty("TOTAL%", Double.class.getName())

I hope this helps.

Upvotes: 0

Alex K
Alex K

Reputation: 22857

This is working code based on example from DynamicJasper official site.

DynamicReportBuilder drb = new DynamicReportBuilder();
drb
        .setTitleStyle(titleStyle)
        .setTitle("Report with grand total")
        .setDetailHeight(15).setHeaderHeight(10)
        .setGrandTotalLegend("Grand Total")
        .setGrandTotalLegendStyle(footerStyle)
        .setDefaultStyles(titleStyle, null, headerStyle, detailStyle)
        .setPrintColumnNames(true);

AbstractColumn columnState = ColumnBuilder.getNew()
        .setColumnProperty("state", String.class.getName())
        .setTitle("State").setWidth(85)
        .build();

AbstractColumn columnBranch = ColumnBuilder.getNew()
        .setColumnProperty("branch", String.class.getName())
        .setTitle("Branch").setWidth(85)
        .setStyle(detailStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnnProductLine = ColumnBuilder.getNew()
        .setColumnProperty("productLine", String.class.getName())
        .setTitle("Product Line").setWidth(85)
        .setStyle(detailStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnnQuantity = ColumnBuilder.getNew()
        .setColumnProperty("quantity", Long.class.getName())
        .setTitle("Quantity").setWidth(80)
        .setStyle(rightAlignedStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnAmount = ColumnBuilder.getNew()
        .setColumnProperty("amount", Float.class.getName())
        .setTitle("Amount").setWidth(90).setPattern("$ 0.00")
        .setStyle(rightAlignedStyle).setHeaderStyle(headerStyle)
        .build();

drb.addGlobalFooterVariable(columnAmount, DJCalculation.SUM, footerStyle);
drb.addGlobalFooterVariable(columnnQuantity, DJCalculation.SUM, footerStyle);

drb.addColumn(columnState);
drb.addColumn(columnBranch);
drb.addColumn(columnnProductLine);
drb.addColumn(columnnQuantity);
drb.addColumn(columnAmount);

drb.setUseFullPageWidth(true);

The output result is:

Generated result at JasperViewer

Upvotes: 1

Related Questions