Display “No Data” message when table is empty in BIRT Report

天大地大妈咪最大 提交于 2019-11-28 01:21:04

问题


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.


回答1:


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:

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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/25425876/display-no-data-message-when-table-is-empty-in-birt-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!