• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Is dynamic columns possible in Jasperreport

 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement where I don't know how many columns my report is going to display until runtime. For example lets say if i want to display a report with 10 columns, first i should print the data with 4 columns followed by next 4 columns and the next 2 columns data.
Is it possible?
Please give me some ideas.....
Thanks
 
Rajan Chinna
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joel McNary

Is it possible to do this in jasperreport???
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've discovered that just about anything is possible in JasperReports. The problem here is that I don't think you can do this without interfacing with the JasperDesign object at runtime. That is, create your report with 1 column, and then at runtime load the design object and programatically change the columns.

If the API doesn't support it, you could always change the API to support it. (Jasper is OpenSource....)
 
Rajan Chinna
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joel,

Do u think i can follow these steps ???
1. create .jrxml file programatically and dynamically.
2. compile it during runtime.
3. load data.
4. generate report.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use IReport to create a template configuration file where you can set the font and other cosmetic things. Once you have finalised the looks then you can read the template xml configuration file at runtime and use JDOM to insert new columns or delete init columns. It involves very basic XML parsing and then rewriting the XML file back to the disk with new 'field' and other corresponding elements . Then jasperreport can pick the xml file from there.

One option could be to give jasperreport a runtime document object, but I havent tried it. Let us know if you can work around with it this way.

also refer to the dtd and before working on configuration file. Note that the XML file requires the elements to be in the same order as in the DTD. Some times when you insert new elements under the root they are inserted at the end of the document

Hope it helps

Amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic