Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 684
CamelCase Avatar asked Dec 18 '13 02:12

CamelCase


2 Answers

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.

like image 54
Sharad Avatar answered Sep 29 '22 12:09

Sharad


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.

like image 31
Jan Bodnar Avatar answered Sep 29 '22 14:09

Jan Bodnar