CamelCase
CamelCase

Reputation: 233

Print No Data Set Band for Empty Dataset

I have a report which has a dataset. I want to print No Data Band whenever the query in the dataset returns 0 records (empty dataset).

I have set the "When No Data" to "No Data Section". But it doesn't seem to be working.

Any Suggestions?

Upvotes: 9

Views: 20646

Answers (3)

ziMtyth
ziMtyth

Reputation: 1048

When I've tried the solution proposed by @Sharad I have found another way, in my approach no need to add No Data band:

  1. Right-click the report to open the report property section
  2. Set When No Data property to All Sections, No Detail

The final result will be the same report with no detail. In my case it responds to my needs perfectly.

PS: I used iReport 4.0.2

Upvotes: 1

Jan Bodnar
Jan Bodnar

Reputation: 11637

For those like myself, who do not use JasperSoft or older iReport and directly work with XML, do the following:

<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"
              whenNoDataType="NoDataSection"
              name="freport" pageWidth="595" pageHeight="842" 
              columnWidth="555" leftMargin="20" rightMargin="20"
              topMargin="20" bottomMargin="20">

Add whenNoDataType="NoDataSection" to the <jasperReport> element.

<noData>
    <band height="15">
        <staticText>
            <reportElement x="0" y="0" width="200" height="15"/>
            <box>
                <bottomPen lineWidth="1.0" lineColor="#CCCCCC"/>
            </box>
            <textElement />
            <text><![CDATA[The report has no data]]> </text>
        </staticText>
    </band>
</noData>

Add <noData> element below the detail band.

Upvotes: 2

Sharad
Sharad

Reputation: 3548

In order to print No data band whenever the query in the dataset returns 0 records(empty dataset) follow these steps:-

  1. Go to Report Inspector and add No Data band in the report
  2. Put static text, such as No Data Found
  3. Right-click the report to open the report property section
  4. Set When No Data property to No Data Section

After adding No data band whenever query will return 0 record "No Data" band will display the static text.

Upvotes: 15

Related Questions