Home
Analytics
Display message if no data
cypherdj
Hi,
I have built a report which contains 2 tables and 2 graphs. Depending on parameters, it sometimes happens that there is no data to display in one of the 2 tables.
Birt does not display the graph if there is no data, which is fine, but how can I hide the table or show a row indicating there is no data for the specified criteria?
Thanks in advance,
Cedric
Find more posts tagged with
Comments
LetsBIRT
Cedric,
you should be able to do that.
At the table onCreate, declare a variable CountofRows = 0;
Then on the onCreate on the Row level do this:
row=this.getRowData( );
countOfRows += 1;
Add a label from the palaette on the report(not in the table, should be after the table) and label it as - No Data to Display, now add this code in its onCreate:
if( countOfRows == 0 ){
this.getStyle().fontStyle = "italic";
this.getStyle().fontSize = "large";
}else{
this.text = "";
}
Let me know if this works.
mwilliams
It's a little more complicated than that cause you have to use persistentGlobalVariables to pass the countOfRow variable around, but that's pretty much it. You'll probably want to initialize the persistentGlobalVariable in the initialize method of the report. Also, to get rid of the header row (if you want to), you can put a check on the countOfRow variable and then use this.getStyle().visibleFormat = "all"; in the onRender method of the table.
Hope this helps.
LetsBIRT
Michael,
I did not declare it as persistentGlobalVariable, but it still works.
I think, when you declare a variable on the Table.onCreate( ) method it would be global because Table.onCreate( ) executes before any rows are retrieved.
Thanks.
mwilliams
Hmmmm...it didn't recognize the variable in the OnCreate method of the label when I set it in the OnCreate method of the detail row. I'll have to look into that. However, I think it has to be a persistentGlobalVariable to pass it to the onRender section of the table to get rid of the header, but that's only needed if it is desired to get rid of the header row.
mwilliams
Oops...I see where I had goofed...I accidentally put the declaration of that variable in the detail row script, not the table.
mwilliams
I was also wrong in my previous post about needing to have it as a PGV to pass to the onRender method. I tested it with the variable declared in the correct spot and it works just fine. My bad on that
.
LetsBIRT
How did you turn off the header?
I cant seem to get this.
mwilliams
There is a problem with that now that I changed the parameter so that there is data for the table. It seems that when the onRender of the table happens the variable is still 0, so the entire table or header (depending on where you put the script) disappears anyways...I'll have to work on it a little more to see if there's a way to drop the header if there's no data.
LetsBIRT
Michael,
I think the thing that you said about PGV to ged rid of the header row is correct.
I declared the variable counter as PGV and initialised it on the
Table.onCreate(), incremented the counter on the row level and retrieved this PGV the onRender of the table and was able to get rid of the header row.
Thanks.
cypherdj
Thanks so much for spending so much of your own time on this guys, really appreciated. I'll definitely give this a blast first thing tomorrow!
I think it would be nice to have this kind of functionality - maybe a new property of tables : No data message, that can be customised/internationalised. If not provided, previous behaviour (or no table rendered).
Actually the same behaviour could be applied to charts/crosstabs.
Cedric
Sankari
Hi,
I did all d steps suggested by you....But the header is there with dat label No data....could u give sample for that
Sankari
Hi,
I did all the steps suggested by you to get rid of header row....bt i wont turn off....could you send me a sample for that....
mwilliams
Sankari,<br />
<br />
You can check out an example that I posted in the devShare that does this here:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/devshare/designing-birt-reports/522-birt-display-quot-no-data-quot-when-table-is-empty-example/'>BIRT
Display "No Data" When Table Is Empty Example - Designs & Code - BIRT Exchange</a><br />
<br />
Hope this helps.
Sankari
That version is nt supported....so could u send me d guidelines....
mwilliams
Sankari,
What version of BIRT are you using?