我有一个主要报告称为子报告。此子报表具有使用数据集的表。
我想在桌子上没有记录时显示一条消息。怎么做?
答案 0 :(得分:4)
带有所需文本的“假” staticText (例如,无数据文本)与表组件后面的表组合表组件的strong> whenNoDataType 属性应解决此任务。
SELECT * FROM sys.dm_db_persisted_sku_features
在 Jaspersoft Studio ( JSS )中,设计如下:
如果我们为Table的数据集应用 “All Section No Detail” 值( whenNoDataType 属性):
<?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="Blank_A4_27" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="95f68ce4-441a-425c-88fb-b48fe96fac6b">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Empty Dataset1" uuid="21916aaf-ceb1-456b-a45e-6c31863ac208"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="252" splitType="Stretch">
<staticText>
<reportElement x="0" y="40" width="555" height="35" uuid="ff8a82ab-c00f-422a-a907-06d4021b87bd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="18" isBold="true"/>
</textElement>
<text><![CDATA[No data]]></text>
</staticText>
<componentElement>
<reportElement x="0" y="20" width="555" height="200" uuid="1a91c926-a553-4eab-bc04-938c1a962f9a">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Empty Dataset1" uuid="1834081e-7aa0-4719-a0ac-e077f259cc18">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="555" uuid="eb741b0d-640c-48d1-b653-03703ce9e27e">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:columnHeader style="Table_CH" height="30"/>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30"/>
</jr:column>
</jr:table>
</componentElement>
</band>
</title>
</jasperReport>
显示空表的结果将是:
如果删除此属性( whenNoDataType 为NULL),结果将为:
在这种情况下, jrxml 中的 Table 标记将为:
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">