Jump to content

Dynamical number of cols


resign

Recommended Posts

Hello,

Is it possible to insert parameters to report, which let me present a table with dynamical number of columns?

The idea is: the user have the possibility to select any cols and export it to pdf as a table.

Data to selected from:
First name, last name , birth date, phone, mail

The user wants to see
last name, phone

Any ideas?

Thanks,

resign

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 If your not doing it in java code then the way I have done this is with parameters and subreports.

Your sql statement should have something like this,

IF ($P!{numberOfCols} = 4)

BEGIN

SELECT $P!{columnOne} as columnOne, $P!{columnTwo} as columnTwo, $P!{columnThree} as columnThree, $P!{columnFour} as columnFour FROM sourceTable

END

In my edit I added the "as columnOne", I realized that is part of the key to solving for your need. This way the report doesn't care what you actually put in columnOne so long as the type is correct. I recommend using string for everything.

You just call the subreport that will result in the correct column number, you could do this several ways but a couple ideas, have subreports for each column count depth and call the one that equals the column count. Or ... make one as wide as the greatest width of columns and set all the extra columns to null and use the option "blank when null".

For the column headers you can have a variable declaration that would set the column headers text dynamically. Something like this,

( $P{columnOne},equals("addressColumn") ) ? "Address" : $P{columnOne},equals("firstNameColumn") ) ? "First Name" : ""

etc, etc, until all the possibiltiies are met.

Hope this helps set you in a direction..

Clark



Post Edited by cmatthews at 07/09/2012 16:30
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...