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

主宰稳场 提交于 2019-12-10 23:14:38

问题


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?


回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/49623525/how-to-display-sum-of-each-columns-at-footer-in-jasperreports-without-groups-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!