How to hide ColumnHeader band when no detail?

By: ka4sri_1999 - ka4sri_1999
How to hide ColumnHeader band when no detail?
2006-05-01 22:40
Hi,

I would like to hide the column header band when there is no data available in the detail band.How do I implement this?

Any help/pointers would be appreciated.

Thanks & Regards
Subashree




By: Craig Butts - craigbutts
RE: How to hide ColumnHeader band when no det
2006-05-02 14:11
Subashree,
Use the "Print When Express" in the Column Header Band Property. Your expression will look something like this:

new Boolean (
( $F{field_name} == null )
)

Hope this helps.
Craig...




By: ka4sri_1999 - ka4sri_1999
RE: How to hide ColumnHeader band when no detail?
2006-05-03 01:24
Hi,
Thanks for the response. Is there any other way to do this? Becoz teh column header should be hidden only if all the fields in the detail band is null. That being the case the expression will become large if each and every field needs to checked for null. Hence wud like to know is there any other way to do the same?

Thanks & Regards
subashree




By: Craig Butts - craigbutts
RE: How to hide ColumnHeader band when no detail?
2006-05-03 07:34
That's the only way I know of doing what you're wanting to do. I haven't been working with iReport/JasperReports that long so maybe someone else knows of a more elegant way of doing this.

Sorry I couldn't be of more help.
Craig...
2006 IR Open Dicussion's picture
Joined: Aug 10 2006 - 3:24am
Last seen: 15 years 9 months ago

3 Answers:

Hi all,

I have the same problem. But this solution didnt work because all fields are not null even though on the last page no details are displayed.
For testing purposes I displayed a field in the columnHeader. Result: On the last page, where no details are displayed, the field in the columnsHeader has the value from the last displayed detail on the last page.

Has anyone an idea how it works correctly?
Fek's picture
Fek
37
Joined: Jun 12 2007 - 11:54pm
Last seen: 14 years 11 months ago

 I solved this by setting all components  in column header their "key" property like this "header1","header2","header3" etc...

In detail band I set one component which I know for sure that will be shown "key" property= "detailExsists"

Then in java code when I get JasperPrint object I iterate all objects on every page and check if there is a component which "key" property is "detailExists", if I don't find it that means that there is no detail on this page and I remove all components with "key" properties "header1","header2" etc... from that page. 

This method still takes space  for the page header band (its height) but it at least it's empty...

Here's my code:

 

 

 

JasperPrint report = myPrint;

boolean detailFound = false;

for (Iterator<JRPrintPage> i = report.getPages().iterator(); i

.hasNext();) {

detailFound = false;

JRPrintPage page = i.next();

for (Object o : page.getElements()) {

JRPrintElement element = (JRPrintElement) o;

if (element.getKey() != null

&& element.getKey().contains("detailExists"))

detailFound = true;

 

}

if (!detailFound) {

Iterator<Object> itt = page.getElements().iterator();

while (itt.hasNext()) {

JRPrintElement element = (JRPrintElement) itt.next();

if (element.getKey() != null

&& element.getKey().contains("header")) {

itt.remove();

}

}

}

 

 

 



Post Edited by zilex at 05/21/2012 10:17



Post Edited by zilex at 07/07/2012 08:35
zilex's picture
16
Joined: Feb 19 2012 - 11:41pm
Last seen: 4 years 10 months ago

where should I put this java code?

samira.726472 - 7 years 11 months ago

Actually, you can try to add a group header band instead of the column header, put column header fields to group header, after adding it, you need to remove group header expression to empty, that means don't need to set group expression, and checked 'Reprint Header On Each Page' properties, I just fixed an issue by this way on Jaspersoft Studio 6.4.0, I hope it's helpful

netshowers's picture
Joined: Jul 8 2013 - 10:56pm
Last seen: 10 months 2 days ago
Feedback