Jump to content
We've recently updated our Privacy Statement, available here ×

How to hide ColumnHeader band when no detail?


2006 IR Open Dicussion

Recommended Posts

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...

Link to comment
Share on other sites

  • 1 year later...
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

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?

Link to comment
Share on other sites

  • 4 years later...

 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
Link to comment
Share on other sites

  • 2 years later...
  • 4 years later...

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...