how to skip record when condition met in jasper table? - jasper-reports

I am creating jasper report. I want to skip that rows when condition met on one variable. what I have done selecting all text boxes in table and in printwhenExprssion written
$F{totalApiReceived} >0
this is not printing that rows but blank row is still showing. I have also checked "Remove line when blank" but still blank row is coming in report. I want to skip that row completely.
My text box is like:
<jr:detailCell style="Table 1_TD" height="15">
<textField isBlankWhenNull="false">
<reportElement x="0" y="0" width="100" height="15" isRemoveLineWhenBlank="true" uuid="f8fbbe37-33e4-48de-a70a-ce4aaca5b8d4">
<printWhenExpression><![CDATA[$F{totalApiReceived}>0]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Center">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA["("+$F{carrierType}+")"+" "+ $F{carrierCode}]]></textFieldExpression>
</textField>
</jr:detailCell>

I got the solution by putting
<filterExpression><![CDATA[$F{totalApiReceived} >0]]></filterExpression>
inside the subset tag.

Related

Table shift to left when one column hide in jasper table?

I am using jasper report and trying to make RTL report. My problem is that when I am hiding my column in table using printWhenExpression based on some condition my table shift to left. I am using below code to hide column in table.
<jr:column width="160" uuid="f9b26e92-337e-4fb9-a091-4a81469c6c49">
<printWhenExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")]]></printWhenExpression>
<jr:columnHeader style="ColumnHeader" height="30" rowSpan="1">
<textField>
<reportElement style="ColumnHeader" x="0" y="0" width="160" height="30" uuid="b4043ada-2580-4602-9262-3791ce3c0807"/>
<textElement>
<font size="8" isBold="true" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$R{target.external.id}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement style="TableTextContent" x="0" y="0" width="160" height="20" isPrintWhenDetailOverflows="true" uuid="9dc36daa-d5e5-417c-831d-ff1b92ef1b79"/>
<textElement>
<font size="8" isBold="false" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{personExternalId}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
is there is any way so that my table should not shift to left when one of its column which is on left in that table is dynamically hide?
If you want to keep the column and does not want text, remove print when condition on column and add it to text expression :
<textFieldExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")?$R{target.external.id} : ""]]></textFieldExpression>

Serial Number Repeating in Jasper Reports

I have used $V{REPORT_COUNT} TO DISPLAY SERIAL NUMBER OF THE RECORDS.For Each Record that is fetched from the database the serial number is displayed correctly.
However if one record that is printed has data more then it can accommodate on a page, it is displayed on the next page. I am fine with that too, however the serial number is again shown for that page Eg. 3 is the serial number and if 3 could not be accommodated on the same page the record is written in the next page and the order of serial number is 1 2 3 (First Page) 3 4 5 etc(second Page).
I want 3 to be displayed only once in the first page and not in the second page. I have uploaded a image of my layout and I do not want to show the circled part I am Using Ireport to design the page
Text Field Properties
This is for the REPORT_COUNT TEXTFIELD
<reportElement
mode="Opaque"
x="0"
y="0"
width="15"
height="30"
backcolor="#D3D3D3"
key="textField-9"
stretchType="RelativeToBandHeight"
positionType="Float"
isPrintRepeatedValues="false"
isRemoveLineWhenBlank="true"
isPrintWhenDetailOverflows="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Times New Roman" pdfFontName="Times-Bold" size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
This properties for the right hand side text box which displays data:
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Opaque"
x="12"
y="0"
width="523"
height="13"
forecolor="#000000"
backcolor="#D3D3D3"
key="textField-2"
positionType="Float"
isRemoveLineWhenBlank="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement verticalAlignment="Middle">
<font fontName="SansSerif" pdfFontName="Times-Bold" size="8" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[" "+$F{vesselName}+($F{type} == null ? "" : " ("+$F{type}+")")]]></textFieldExpression>
</textField>
Can you just tell us the properties you have set for the text fields?
I have just made a rough design of your scenario and I did not come across your issue. The row_count value is not getting repeated.
Refer below image.
Set a few properties to your variable:
<variable name="RECORD_COUNT" class="java.lang.String" incrementType="Column" calculation="Count">
<initialValueExpression><![CDATA[1]]></initialValueExpression>
</variable>

How to merge multiple rows in report?

I wanted to merge multiple rows in JasperReports's report without using crosstab. Is it achievable?
Here I have pasted my jrxml code for removing duplicate printing, but it keep lines around the cell although there is no record inside.
<textField pattern="dd.MM.yyyy" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="110" height="21" isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{DEPARTURE_DATE}]]></textFieldExpression>
</textField>

different pages on change of group in jasper reports

My report groups contains 4-5 table component which will be printed each time when group changed.I don't want to print multiple entries of same group in the table components inside the group.
<textField>
<reportElement x="150" y="0" width="60" height="20" isPrintRepeatedValues="false" />//**isPrintRepeatedValues="false"**
<textElement textAlignment="Left">
<font isBold="false" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{activityname}]]></textFieldExpression>
</textField>
<textField>

How do I hide a table column based on its content?

I have a report which contains a table. I would like to hide the columns of that table based on the result set of the query that backs the table. As an example, here is the XML for one of the columns:
<jr:column width="80">
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="30" style="table_CH"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1_header}</textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1}</textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
For some reason, my report is complaining about the printWhenExpression. It claims that $F{Total1_header} does not exist. It does not complain however about the instance of $F{Total1_header} in the textFieldExpression.
I can't figure out why the field is avaiable for the textFieldExpression, but not the printWhenExpression.
Column has 'Column print when' property to hide/show the column by an expression.
Another way to delete columns is to modify the jasper design at runtime, then report compilation and then procees as usually. This method makes it possible to distribute unused width to remaining columns.
Roughly goes like this:
JasperDesign design = ...
JRDesignComponentElement tableElement = (JRDesignComponentElement) design.getTitle().getElementByKey(tableKey);
StandardTable tableComponent = (StandardTable) tableElement.getComponent();
col = tableComponent.getColumns().get(0);
tableComponent.removeColumn(col);
// Then compile the JasperDesign
JasperReport result=JasperCompileManager.compileReport(design);
For future readers
You should use this
<printWhenExpression><![CDATA[$F{Total1_header} != null]]></printWhenExpression>
Instead of
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>