Jump to content
We've recently updated our Privacy Statement, available here ×

Conditional Expression for TextField


p.meher09

Recommended Posts

I am adding conditional style for textField, I want to display all the negative number in a different color, but the conditional style are applying to entire row instead of the current field. Please suggest how to enable it to a particular filed only? 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I can think of two possible places to check.

  1. a rectangle element would have been inserted with the conditional style behind the textfields
  2. all the textfields would have been applied with the conditional style

sample code below

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  --><!-- 2017-01-27T12:54:46 --><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_3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="05e26242-e3d0-4d1d-be44-111aa4ea6c1e">    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <style name="Style1">        <conditionalStyle>            <conditionExpression><![CDATA[$F{NAME}.equals("three") ? true : false]]></conditionExpression>            <style mode="Opaque" backcolor="#FF0400"/>        </conditionalStyle>    </style>    <queryString>        <![CDATA[select 1 as id, 'one' as name from dual unionselect 2 as id, 'two' as name from dual unionselect 3 as id, 'three' as name from dual unionselect 4 as id, 'four' as name from dual unionselect 5 as id, 'five' as name from dual unionselect 6 as id, 'six' as name from dual]]>    </queryString>    <field name="ID" class="java.math.BigDecimal"/>    <field name="NAME" class="java.lang.String"/>    <background>        <band splitType="Stretch"/>    </background>    <columnHeader>        <band height="30" splitType="Stretch">            <staticText>                <reportElement x="0" y="0" width="80" height="30" uuid="07f0751f-5ca6-4399-bbe1-db596394f33c"/>                <text><![CDATA[iD]]></text>            </staticText>            <staticText>                <reportElement x="80" y="0" width="100" height="30" uuid="33ec7d70-67e1-4b18-b873-5feb713fba0e"/>                <text><![CDATA[NAME]]></text>            </staticText>        </band>    </columnHeader>    <detail>        <band height="30" splitType="Stretch">            <textField>                <reportElement x="0" y="0" width="80" height="30" uuid="ed6d0f1f-c0bf-430b-b0ed-6ac1f98c7a9d"/>                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>            </textField>            <textField>                <reportElement x="80" y="0" width="100" height="30" uuid="7cb02ed3-ac3e-44d7-a61c-c50723f18ea1"/>                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>            </textField>        </band>    </detail></jasperReport>[/code]
Link to comment
Share on other sites

My problem is I am applying same style to all column, let's say "style1" to three column, and in column 3 one value is -ve, so the conditional style is applying to entire row when value is negative. Do we need to apply different style name for each column?
Please advice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...