Display "No Data" message when table is empty in BIRT Report
Asked Answered
H

3

6

I want to hide a table and to report that "No Data" message is present if the query returns no data. In computed columns i have added the columns which counts the number of rows present(i.e.TableCheck). and i have created label just below the table with the message "No Data". In script onCreate i have added the below code.

if( countOfRows == 0 ){
this.getStyle().fontStyle = "italic";
this.getStyle().fontSize = "large";
}else{
this.text = "";
}

countOfRows = 0 is initialize in script.

In table visibilty propery, checked the Hide Element and added the below code in expression.

if (row["TableCheck"] == null){
    true
}
else{
    false
}

Problem: When dataSet is empty "No Data" Message is displaying.But when data set is not empty, then error message is not hiding.

Please let me know how to fix this.

Thanks in Advance.

Hennebery answered 21/8, 2014 at 12:2 Comment(2)
Related Need to display a message when chart not having data in birt reportIlluminator
Related Hiding grids/tables in BIRT whith no results from datasourcePotassium
K
12

Do it this way: First add visual elements to display it when data set doesn't return any row.

Then define global variable in Initialize script of report root. For example

rowsReturned = 0;

On your table that you'll evaluate data set to see is there rows returned on Visibility tab set next:

enter image description here

On elements you want to display whene there is no returned data set this on Visibility tab

enter image description here

Kitchen answered 21/8, 2014 at 12:22 Comment(3)
Thank you very much.This is what i am expecting.Hennebery
The visibility expression must not contain a trailing semicolon.Pustulant
Maybe, but this screenshots are made from production report ;)Kitchen
S
4

If you want to hide the table when no data returned, you can write this in its Visibility property:

row.__rownum < 0

and in Visibility property of your "No Data" message you use the opposite check:

row.__rownum >= 0

Note that both components must be bound to the data set you want to check. In the case of the message component you can achieve this putting it in a header or footer row.

Stoll answered 17/9, 2014 at 13:50 Comment(0)
P
1

Alternative solution without using global variables (though functionally not quite the same, because the layout will always contain a table):

Add a binding numRows for the COUNT aggregate with the expression 1 to the table.

Set as visibility expression on the table header row:

!row["numRows"]

Add a new footer row to the table; for this footer row set the visibility expression

row["numRows"]

Merge the cells in this footer row, then place a label "No data found" into the table cell.

Pustulant answered 22/8, 2014 at 12:37 Comment(2)
There's a bug in BIRT 4.3: The COUNT aggregate on the expression 1 does not work (returns 1 for 0 rows!). Instead, choose an arbitrary NOT NULL column as the expression.Pustulant
Bug seems to still exist in Innovent Solution's BIRT 4.8 release.Ency

© 2022 - 2024 — McMap. All rights reserved.