如何在jasper报告中添加按钮? [英] How can I add a button in jasper report?

查看:93
本文介绍了如何在jasper报告中添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to add a button in the report, which any action will be fixed?

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

Example: Button "View", which will show more detailed statistic.

评论:

我不完全理解如何制作文本元素的按钮

推荐答案

要创建按钮,请创建 textField with hyperlinkType =Reference hyperlinkReferenceExpression

To create a button, create a textField with hyperlinkType="Reference" and a hyperlinkReferenceExpression

示例

<?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,因此它会在新页面中打开。

when clicked it will direct you to the value of the hyperlinkReferenceExpression, in example I have also set hyperlinkTarget="Blank" so it opens in a new page.

有关这些属性的其他信息,请参阅 JRHyperLink API

For additional information on the attributes see JRHyperLink API

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

Hey I want my button to change color when I pass over it....

没问题,(只要导出是html,在pdf中你需要用注释做一些技巧,但我会把它留下来......)。

No problem, (as long as export is html, in pdf you need to do some tricks with annotation but I will leave this out..).

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

I have added some css tags on the textElement see the property under the reportElement

所以一些简单的css。

So some simple css.

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

最后,如何将此css放入输出文件?

导出自定义HTML模板

如何将css添加到jasper报表服务器

这篇关于如何在jasper报告中添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆