我有一个碧玉的报告列表控件,可以从后端获取动态值。我需要在两列中显示列表值。
我怎样才能做到这一点?
这是我的jr:list
代码
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
<datasetRun subDataset="accessorialsDataset" uuid="b0e600e0-5797-42b4-8078-12dd4231dd3d">
<dataSourceExpression><![CDATA[$P{accessorialDataSource}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="12" width="524">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" x="0" y="0" width="259" height="12" uuid="221d3ff4-39a7-4ddd-bc74-50bed600819b"/>
<textElement>
<font fontName="Liberation Sans" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{accessorial}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
最佳答案
要在jr:list
组件集printOrder="Horizontal"
上实现多列,然后将jr:listContents
宽度指定为您需要相对于包含jr:list
的reportElement的列数的倍数
2列示例
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="2 columns" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="308cb8ae-e40a-45f4-a347-c6fcdad320b1">
<subDataset name="Dataset" uuid="ad0d45f0-00f0-495c-bff4-ae70340e05d4">
<queryString>
<![CDATA[]]>
</queryString>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<summary>
<band height="30">
<componentElement>
<reportElement x="0" y="0" width="550" height="30" uuid="f811df99-b6ad-4157-a818-42ed4b77c2f0"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
<datasetRun subDataset="Dataset" uuid="30dc2e8a-06f9-4ecf-aa8d-66d5edd6fb95">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList("Item1;Item2;Item3;Item4".split(";")))]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="275">
<textField>
<reportElement x="0" y="0" width="270" height="30" uuid="2500a411-7ad6-4148-958f-34dfae2c9346"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</summary>
</jasperReport>
注意:
printOrder="Horizontal"
和那个jr:listContents width="275"
是reportElement的
width="550"
的1/2输出量