ssangadi276
ssangadi276

Reputation: 159

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

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.

Upvotes: 6

Views: 12036

Answers (3)

kelgwiin
kelgwiin

Reputation: 817

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.

Upvotes: 4

hvb
hvb

Reputation: 2669

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.

Upvotes: 1

Miki
Miki

Reputation: 2517

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

Upvotes: 12

Related Questions