How can I add a button in jasper report?

后端 未结 1 936
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 15:00

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.

1条回答
  •  天命终不由人
    2020-12-21 16:03

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

    Example

    
    
    
        <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>
    
    
    

    Will generate

    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.

    For additional information on the attributes see JRHyperLink API

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

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

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

    So some simple css.

    
    

    Finally, how do I put this css in the output file?

    Export custom HTML template

    How to add css to jasper report server

    0 讨论(0)
提交回复
热议问题