下图显示了我在ireport中的交叉表:
我想按特定顺序对列进行排序,因为我知道在交叉表数据中,我放置了一个具有以下属性的对象列表List<ChampEtatAteliers>
:
public class ChampEtatAteliers {
private String numero;
private String denominationFr;
private String etatEntreeSortie;
public ChampEtatAteliers(String numero, String denominationFr, String etatEntreeSortie) {
this.numero = numero;
this.denominationFr = denominationFr;
this.etatEntreeSortie = etatEntreeSortie;
}
}
etatEntreeSortie
显示在列中,denominationFr
显示在行中,numero
用于交叉表中的计数
String rapportLien = "/SituationEquipement.jasper";
Map parametres = new HashMap();
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(atelierses);
在java中我将这些对象放在列表atelierses
List<ChampEtatAteliers>
中,所以有没有办法对列表或交叉表ireport中的列进行排序,我在ireport上的xml代码如下:
<columnGroup name="nbreVehicule" height="66">
<bucket order="Descending" class="java.lang.String">
<bucketExpression><![CDATA[$F{nbreVehicule}]]></bucketExpression>
<orderByExpression><![CDATA[$V{MyOrderByField_measure}]]></orderByExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="85" height="66" uuid="2109b261-1b20-493a-b664-ce59731c4a20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{nbreVehicule}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="MyOrderByField_measure" class="java.lang.Integer" calculation="Nothing" >
<measureExpression><![CDATA[$F{myOrderByField}]]></measureExpression>
</measure>
答案 0 :(得分:0)
在jasper报告中,通过在columnGroup
<上设置order
属性,可以将交叉表bucket
排序为升序或降序 / p>
示例强>
<columnGroup name="GROUP" height="16" headerPosition="Center">
<bucket order="Descending" class="java.lang.String">
<bucketExpression><![CDATA[$F{MyField}]]></bucketExpression>
</bucket>
.....
</columnGroup>
如果您需要用户定义订单,则应使用orderByExpression
为您要订购的内容定义一个度量
<measure name="myOrderByField_measure" class="java.lang.Integer" calculation="First">
<measureExpression><![CDATA[$F{myOrderByField}]]></measureExpression>
</measure>
使用orderByExpression
<columnGroup name="GROUP" height="16" headerPosition="Center">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{myField}]]></bucketExpression>
<orderByExpression><![CDATA[$V{myOrderByField_measure}]]></orderByExpression>
</bucket>
.....
</columnGroup>
在您的示例中,可以通过在ChampEtatAteliers
类示例private int myOrderByField;
中引入新字段,然后根据需要通过代码设置来实现此目的。
另一种解决方案,就是将自己的对象(类)返回为MyField
并实现Comparable,生成所需的顺序。
编辑:工作,OP无法使orderByExpression
正常工作。
由于myOrderByField
与nbreVehicule
是唯一的(相关的1对1),因此他可以在myOrderByField
bucketExpression
<measure name="nbreVehicule_measure" class="java.lang.String">
<measureExpression><![CDATA[$F{nbreVehicule}]]></measureExpression>
</measure>
<columnGroup name="nbreVehicule" height="66">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{myOrderByField}]]></bucketExpression>
</bucket>
....
<textFieldExpression><![CDATA[$V{nbreVehicule_measure}]]></textFieldExpression>
.....
</columnGroup>
因此bucketExpression
不一定要与crosstabColumnHeader