Jump to content
Changes to the Jaspersoft community edition download ×

Updating the jrxml at runtime


manick

Recommended Posts

Hi All,

Can anyone please let me know whether it is possible to add a new column to the jrxml obtained by using the iReport tool? If yes, please let me know the details for doing so.

I need to implement a requirement which requires adding columns to the report after the result set is obtained.

 

Regards,

Raja

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I don't think you can do that because you need to compile the JRXML before you fill it. If you were compiling and running the report through a java app outside of iReport you would use code like:

Code:

JasperDesign jd = new JasperDesign();
jd = JRXmlLoader.load(jrxml_filename);
jd.setColumnCount(6);

Then you compile the JRXML and fill it.

Link to comment
Share on other sites

Hi,

 

First of all, let's agree about terms: what kind of columns are you taking into account?

Columns have 2 meanings in jasperreports:

- when talking about 'columncount' property, this has nothing to do with your queries and result sets; it says just how many vertical simmilar fill areas do you want to see on your page. Take a look at the FirstJasper sample: there the columncount is set to 2, and there are 2 simmilar vertical areas.

- your post was talking about result set: here is the other 'column' meaning - columns returned from your datasource after query execution.

In this second case, I think there might be a possibility: if you know at design time ALL column names, then write the jrxml as containing ALL those columns, write the query so to return always all those columns, but associate all column related textfields with a printWhenExpression, in order to make them visible only when that condition is true. Don't forget the column headers and footers too.

 

hth,

sanda

Link to comment
Share on other sites

My requirement falls under second case. But the issue is I won't be aware of all columns at design time. I have to get the result set and based on the results in the result set I have to add the columns to the jrxml.
Link to comment
Share on other sites

Ok, the other (more complicated) possibility is to dinamically get your design object after executing the query. In order to do so, when you have the result set let it be your new datasource, and write by your own the desired JasperDesign object, according to columns present in the result set (I mean, you have to write a JasperDesign generator method, with the result set as argument, in order to determine relevant columns).

For more information about howto do it, take a look at the noxmldesign project sample.

 

hth,

sanda

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