Jump to content

Number of rows in a group


Marcus W
Go to solution Solved by Marcus W,

Recommended Posts

hi

I have a (1st) group CITY and a (2nd) group JOB. I want to show the number of detail rows in the CITY group footer. How is that done? I've tried so many things, but I got 1 or another wrong number.

CITY: city-1
JOB: expert
DETAIL: person-1
DETAIL: person-2
JOB: CIO
DETAIL: person-3
CITY FOOTER: size should be 3

CITY: city-2
JOB: Developer
DETAIL: me
CITY FOOTER: size should be 1

greetz

// JR 6.0

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I've tried that before. It does not work.

I put a text field with expression $V{city_COUNT} with the evaluation times Now, city-Group, Auto and Band and it all returns 1.

    <group name="city">
        <groupExpression><![CDATA[$F{city}]]></groupExpression>
... 
    <groupFooter>
            <band height="21">
                <textField evaluationTime="Group" evaluationGroup="city">
...

                    <textFieldExpression><![CDATA[$V{city_COUNT}]]></textFieldExpression>
                </textField>

greetz
Marcus

Link to comment
Share on other sites

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2018-04-27T13:15:11 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3605fe68-400a-4623-b614-bfac8e54bcbf">
    <field name="name" class="java.lang.String"/>
    <field name="city" class="java.lang.String"/>
    <field name="job" class="java.lang.String"/>
    <group name="city">
        <groupExpression><![CDATA[$F{city}]]></groupExpression>
        <groupHeader>
            <band height="20">
                <property name="xmap.band.label" value="Stadt"/>
                <textField>
                    <reportElement mode="Opaque" x="30" y="0" width="100" height="20" backcolor="#9E9E9E" uuid="7f9d7949-ad5e-43a1-ade4-bca49e0ce54f"/>
                    <textElement>
                        <font isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="21">
                <textField evaluationTime="Group" evaluationGroup="city">
                    <reportElement mode="Opaque" x="374" y="0" width="180" height="20" backcolor="#9E9E9E" uuid="b34e24e8-32e5-432a-8829-3393f8a3f072"/>
                    <box>
                        <pen lineWidth="0.0"/>
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <paragraph rightIndent="3"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{city_COUNT}]]></textFieldExpression>
                </textField>
                <line>
                    <reportElement x="0" y="0" width="554" height="1" uuid="05968feb-a8da-4020-afa2-f51ede363560"/>
                </line>
            </band>
        </groupFooter>
    </group>
    <group name="job">
        <groupExpression><![CDATA[$F{job}]]></groupExpression>
        <groupHeader>
            <band height="20">
                <property name="xmap.band.label" value="Beruf"/>
                <textField>
                    <reportElement mode="Opaque" x="350" y="0" width="100" height="20" backcolor="#D6D6D6" uuid="9bf7b715-5293-4bae-947e-9fe868123347"/>
                    <textFieldExpression><![CDATA[$F{job}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
    </group>
    <title>
        <band height="49" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="0" y="0" width="554" height="30" backcolor="#ADAFC7" uuid="52f7dff6-dbe6-4ca1-9f4e-84cf35d7f162"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <text><![CDATA[title]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="30" y="0" width="100" height="20" uuid="7398460c-3884-4db8-b19a-6e525d4f6e8a"/>
                <textElement>
                    <font isUnderline="true"/>
                </textElement>
                <text><![CDATA[City]]></text>
            </staticText>
            <staticText>
                <reportElement x="140" y="0" width="180" height="20" uuid="6fb25d98-fc8c-4b10-a8e5-9b5485866cf9"/>
                <textElement>
                    <font isUnderline="true"/>
                </textElement>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="350" y="0" width="100" height="20" uuid="219ca020-ed42-4943-b5a3-86626991ead8"/>
                <textElement>
                    <font isUnderline="true"/>
                </textElement>
                <text><![CDATA[Job]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="0" y="0" width="554" height="20" backcolor="#FFFCBD" uuid="73718730-de75-4f20-b25f-c1bb43df055c"/>
                <textField>
                    <reportElement x="140" y="0" width="180" height="20" uuid="8ae082a2-cc19-470c-9ff2-550332a97f1a"/>
                    <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
    <pageFooter>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20" uuid="10a5f956-f48e-4a67-b9a7-0ea94b2d835b"/>
                <text><![CDATA[Page Footer]]></text>
            </staticText>
        </band>
    </pageFooter>
</jasperReport>
 

Link to comment
Share on other sites

As datasource I use JRBeanCollectionDataSource together with a List of some objects of type

public static class Testobject {
        private final String name;
        private final String city;
        private final String job;

        public Testobject(String n, String c, String j) {
            name = n;
            city = c;
            job = j;
        }
        
        public String getName() {
            return name;
        }

        public String getCity() {
            return city;
        }

        public String getJob() {
            return job;
        }
    }

Link to comment
Share on other sites

  • Solution

Oops, sorry, it was my mistake.

The special thing about this tiny test report is that I use this for testing a wrapper for net.sf.jasperreports.engine.JasperReport. Without my wrapper class the values are correct. Now it's my job to find the error in my wrapper. (topic of the wrapper class: band switching on/off at runtime)

Link to comment
Share on other sites

The report missed any information about its datasource, so I ran the report in Jaspersoft Studio using a custom query for the built-in Sample DB datasource, and got the expected results (see attached image). In this case, I think the problem might be related to the datasource used in the report.

Link to comment
Share on other sites

In case of JRBeanCollectionDataSource, make sure your data is properly sorted, in order to get groups as desired. If data are not already sorted in the datasource, use the following sortfields in the JRXML file:

<sortField name="city"/><sortField name="job"/>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...