为什么组在报告中以不同的顺序出现? [英] Why do groups appear in different orders on report?
问题描述
我目前正在尝试使用iReports 5.6.0根据字段类型"将数据分组在一起.似乎可行,但将组分散到不同的地方,请参见下面的示例:
I am currently trying to group data together based on a field "type" using iReports 5.6.0. It seems to work but spreads the groups into different places see example below:
会发生什么
ID Name Location Type Cost
1 C1 FRA Car 2k
2 C1 FRA Car 2k
3 Transit USA Van 10K
4 Custom USA Van 20K
5 C2 FRA Car 4K
预期结果:
Example Data
ID Name Location Type Cost
1 C1 FRA Car 2k
2 C1 FRA Car 2k
5 C2 FRA Car 4K
3 Transit USA Van 10K
4 Custom USA Van 20K
我希望数据能像下面的预期结果那样出现,而不是像分组那样被拆分(我认为这是订单数据从应用程序馈送到报表中的原因)
I wish the data to come out as the expected result below instead of groups seem to be split up (which I think is it the order data is fed into the report from the application)
我尝试使用保持在一起"选项,但在这种情况下似乎不起作用.
I have tried using the keep together option but it doesn't seem to work in this situation.
推荐答案
在jasper报告中使用分组获取正确输出数据时 需要根据所使用的组表达式已经订购.
When using grouping in jasper report to get correct output the data needs to already be ordered according to the group expressions used.
您可以通过以下任一方式实现此目标:
You can achieve this by either:
order your datasource through query ORDER BY
or if using custom datasource for example Collections.sort()
或
在报告中使用<sortField/>
元素,例如<sortField name="myField"/>
.
use the <sortField/>
element in the report for example <sortField name="myField"/>
.
-
在iReport IDE中,打开报告查询"对话框编辑查询",然后单击排序选项..."按钮(界面底部)
In iReport IDE open the Report Query Dialog "edit query" and click the "Sort options..." button (bottom of interface)
在JasperSoft Studio中,打开数据集和查询对话框,在底部找到订单"标签,然后添加您的字段
In JasperSoft Studio open the dataset and query dialog, find the tab "Order" at the bottom and add your field(s)
这篇关于为什么组在报告中以不同的顺序出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!