【问题标题】:How can I add a button in jasper report?如何在碧玉报告中添加按钮?
【发布时间】:2016-01-18 20:38:29
【问题描述】:

是否可以在报告中添加一个按钮,任何操作都会被修复?

示例:“查看”按钮,将显示更详细的统计信息。

评论:

我完全不明白如何制作一个文本元素的按钮

【问题讨论】:

  • 你需要更具体,你只是问如何添加一个按钮。你的确切问题是什么?
  • 我有仪表板。我需要添加按钮,当按下它时,有一定的动作。可以用碧玉制作吗?谢谢
  • 当然,它可以在 textElement 上使用锚表达式。如果在过去的一些 jrxml 代码中仍然存在问题,则具有当前的行为,期望的行为。 (编辑问题,问题下的链接)
  • 谢谢,皮特。您不能在描述的地方举个例子或提供参考吗?
  • 我还没有完全理解如何制作文本元素的按钮

标签: jasper-reports


【解决方案1】:

要创建按钮,请使用hyperlinkType="Reference"hyperlinkReferenceExpression 创建textField

示例

<?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="JddButton" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a88eaae-fbef-4a3d-b8bf-0b12bafc985b">
<title>
    <band height="80" splitType="Stretch">
        <textField hyperlinkType="Reference" hyperlinkTarget="Blank">
            <reportElement mode="Opaque" x="150" y="20" width="200" height="40" forecolor="#FFFFFF" backcolor="#009900" uuid="822deecb-059b-4921-bfb7-07ee7cbde26a">
                <property name="net.sf.jasperreports.export.html.class" value="btn"/>
                <property name="net.sf.jasperreports.export.html.id" value="idBtn"/>
            </reportElement>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="24"/>
            </textElement>
            <textFieldExpression><![CDATA["VIEW"]]></textFieldExpression>
            <anchorNameExpression><![CDATA["myButton"]]></anchorNameExpression>
            <hyperlinkReferenceExpression><![CDATA["https://stackoverflow.com/users/5292302/petter-friberg"]]></hyperlinkReferenceExpression>
            <hyperlinkTooltipExpression><![CDATA["Click to view"]]></hyperlinkTooltipExpression>
        </textField>
    </band>
</title>
</jasperReport>

会生成

当点击它时,它会引导你到hyperlinkReferenceExpression 的值,例如我还设置了hyperlinkTarget="Blank",所以它会在一个新页面中打开。

有关属性的更多信息,请参阅JRHyperLink API

嘿,我希望我的按钮在我经过它时改变颜色....

没问题,(只要导出是html,在pdf中你需要对注释做一些技巧,但我会省略这个..)。

我在textElement 上添加了一些css 标签,请参阅reportElement 下的属性

所以一些简单的 css。

<style type="text/css">
    a {text-decoration: none}
    td.btn:hover {
        background-color: yellow !Important;
    }
</style>

最后,如何把这个 css 放到输出文件中?

Export custom HTML template

How to add css to jasper report server

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多