Grouping by parameter value in jasper

核能气质少年 提交于 2019-12-25 12:46:08

问题


Well, I don't know, maybe I'm missing something, but I've been trying to group data in a jasper report, but so far the grouping appears only if the group expression is a field. Is it possible to group data by parameter value instead of field value? i.e., something like

<groupExpression><[!CDATA[$P{some_param}]]></groupExpression>

instead of

<groupExpression><[!CDATA[$F{some_field}]]></groupExpression>

in the .jrxml file?


回答1:


Is it possible to group data by parameter value instead of field value?

Yes, it is, just like you mentioned. You would have no syntax errors and the report would be generated.

The problem is that it may not bring what you're expecting. The group bands are usually printed every time the "groupExpression" changes. So basically this parameter needs to be associated with something that will change during the report generation (for example, filling a parameter of a subreport with a field in way that this subreport uses this paramater as a group expression). And of course, it needs to be associated with something that makes sense and bring you the desirable behavior.

You can have something like this in your subreport:

...
    <parameter name="START" class="java.util.Date"/>
    <parameter name="END" class="java.util.Date"/>
...

And something like this in a detail band of your "super" report:

<subreport>
     <reportElement x="0" y="10" width="555" height="200" uuid="ac2c99da-f595-4498-a518-2bfb1f31b73c"/>
         <subreportParameter name="START">
                <subreportParameterExpression><![CDATA[$F{start}]]></subreportParameterExpression>
         </subreportParameter>
         <subreportParameter name="END">
                <subreportParameterExpression><![CDATA[$F{end}]]></subreportParameterExpression>
         </subreportParameter>
         ...
</subreport>

Just notice I'm assuming the fields $F{end} and $F{start} are also "java.util.Date" objects.



来源:https://stackoverflow.com/questions/24369285/grouping-by-parameter-value-in-jasper

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