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

swap two sub report dynamically


vivek_1

Recommended Posts

I am using jasper report to generate pdf and docx . for design I am using ireport. Suppose I have two subreport  sub1 and sub2 . Now I need to swap position of  these two subreport from each other.

I am using jasper plugin in grails.  now my problem is that how can I change the position of these two sub report from my controller.

If there is any confusion to understand question, feel free to ask me.

Thanks.

Vivek

 

Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

Hi vivek ,

Firstly I want to state that I don't have an idea of grails, but in general I could tell you how to fix this.

See you can put condition in the subreport expressions for the two elements of subreport in the main report.(Subreport expression here means the path of the subreport on the local machine ) and if this path in both the elements is varied on the basis of condition then you would be able to swap the subreports dynamically. Have tested the same in iReports it is working fine.

 

Hope that it helps.

Thanks,

Ankur Gupta

Link to comment
Share on other sites

Hi.

Suppose there are two subreport elements suppose sub1 and sub2

for sub1 the Subreport expression will be( I am putting a static path for the subreport on local disk)
condition?"D://Reports//sub1.jasper":"D://Reports//sub2.jasper"

for sub2
condition?"D://Reports//sub2.jasper":"D://Reports//sub1.jasper"

The condition will be the dynamic value which triggers the swapping of the subreports

 

Hope that the above description helps.

Thanks,

Ankur Gupta

Link to comment
Share on other sites

No its not swapping of two sub report exactly.Its basically rearranging of sub report.Every sub report has its own look and feel and own list which I send through controller. In starting I have a order of sub report suppose 1,2,3,4,5,6,7,8,9 . after change the position of sub reports suppose I have an order like this- 5,9,8,3,2,1,6,7,4 or 8,5,1,9,4,7,6,2,3 or something like this. I have 9! possibillity to rearrange sub report. Now I How can I set path and data(List sent with sub report) to manage my sub report.
Link to comment
Share on other sites

Hi ,

Sorry for a late reply was occupied with some work,

My try would be ,If the cases are 9! 
 
I think you can generate the sequence of 9! ways of arranging the 9 reports(eg- '987654321','987123456',..etc) , then what you can do is put a switch case with each case(1-9) defining the subreport and the every time the random arrangement string is generated , suppose '987165324' then one by one the cases will execute depending upon the generated sequence and generate the subreports also. 
 
See I am not sure you will have to try this logic.Please let me know if it works.
 
Thanks,
Ankur Gupta
Link to comment
Share on other sites

This solution was in my mind. But I am confused that how can I implement switch case in jrxml file. I searched it on google but did not find anything regarding this. Can you tell me or provide some link so that I can learn it better.
Link to comment
Share on other sites

just one more question.

new datasource

"path for subreport.jasper"

 

Can I give dynamic value for x,y and width ,height, like I take a variable and put value. If possible what type of data type should I take?

Link to comment
Share on other sites

Hey I was thinking that you could do this switch case through java program , not xml so you could generate the report including the shuffled subreports

 

Like:

 

 

 

Map parameters = new HashMap();

 

//if you want this to be compiled in runtime

 

JasperReport jasperReport = JasperCompileManager.compileReport(your JRXMLReport path file here);

JasperReport subReport = JasperCompileManager.compileReport(your JRXMLSubReport path file here);

 

//you can notice that there're a lot of overloaded mathods to compile it, you can choose

//what is better in your case

 

//if you want to use the complied file *.jasper

JasperReport jasperReport = (JasperReport)JRLoader.loadObject(new File("filenameReport.jasper"));

 

JasperReport subReport = (JasperReport)JRLoader.loadObject(new File("filenameSubReport.jasper"));

 

 

//Then you add your subReport in your parameter Map

parameters.put("SUBREPORT_JASPER_FILE", subReport);

 

JasperFillManager.fillReport(jasperReport, parameters,

new JRBeanCollectionDataSource(yourList));

 

 

 

This is the code which contains only a single subreport I was pointing that put a switch case with each case generating the subreport as above and dynamically get shuffled and added to the report.

 

Hopwe that it helps

 

Thanks.

 

Ankur Gupta

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