Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JasperReports: How to show data in two columns

This is my current jrxml file:

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="18199607-277f-4e05-b2ba-be2f5d89e7d5">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
    <![CDATA[SELECT
 language.`id` AS language_id,
 language.`name` AS language_name
FROM
 `language` language]]>
</queryString>
<field name="language_id" class="java.lang.Long"/>
<field name="language_name" class="java.lang.String"/>
<title>
    <band height="20" splitType="Stretch">
        <staticText>
            <reportElement uuid="662306ce-d3df-4306-b320-e89a92485da3" x="0" y="0" width="555" height="20"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="14" isBold="true" isItalic="true" isUnderline="true" isStrikeThrough="false"/>
            </textElement>
            <text><![CDATA[Languages]]></text>
        </staticText>
    </band>
</title>
<detail>
    <band height="41" splitType="Stretch">
        <textField>
            <reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="23" y="14" width="231" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="301" y="14" width="235" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="0" y="14" width="23" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="278" y="14" width="23" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
        </textField>
    </band>
</detail>
</jasperReport>

and this is my output:

enter image description here

and I need this:

enter image description here

So how can I show data in two columns from a list.

like image 632
MKB Avatar asked Oct 08 '13 18:10

MKB


People also ask

How do I group columns in Jasper report?

right click on the report in the report inspector and choose Add Report Group. Follow the wizard, set as group name PledgeType and choose Group by the following report object where you select the field PledgeType. Click next. Check Add the group header and click Finish.

How do I merge two columns in Jasper?

To merge the column headers in jasper reports table component, select the columns from "Column Header" section of "Table Outline" and right click on them and then click on "Group columns".

How do I add a column to a Jasper report?

To add a column to a table, right-click the column and choose Create Column After, Create Column Before, Create Column at the Beginning, or Create Column At The End. By default, when Jaspersoft Studio adds a column to a table, the new column inherits the properties of the other columns in the table.


1 Answers

You should set report's property Print order (printOrder) value as Horizontal and the report's property Columns (columnCount) value as 2.

enter image description here

The sample

The jrxml file:

<?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="report39" language="groovy" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8ea55a1a-7e67-4906-b7be-7314b7bfa03d">
    <queryString>
        <![CDATA[SELECT id, name FROM PRODUCT]]>
    </queryString>
    <field name="ID" class="java.lang.Integer"/>
    <field name="NAME" class="java.lang.String"/>
    <detail>
        <band height="61" splitType="Stretch">
            <textField>
                <reportElement uuid="ea1c8668-6d75-42da-9293-6cfd81297c03" x="0" y="0" width="24" height="61"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="652cf497-5bc2-4b62-b47a-23ec135cbfdf" x="24" y="0" width="176" height="61"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

The report's design (in iReport):

enter image description here

The result will be (via preview in iReport):

enter image description here

like image 109
Alex K Avatar answered Nov 04 '22 01:11

Alex K