2004 IR Help Posted August 23, 2006 Share Posted August 23, 2006 By: Jeff - jfsbf Dynamically shift columns in compiled report 2005-09-30 08:03 Is it possible to shift the position of column headers and columns in a compiled report? We have reports that are dynamically built at runtime based on columns user is allowed to see. We would like to use JasperReports for our HTML, CSV and PDF report generation. For instance, one user may see the following: Col1 Col2 Col3 ------ ------ ------ xxxx yyyy zzzz Another user may only need to see columns 1 and 3: Col1 Col3 ------ ------ xxxx zzzz Notice how Col3 (and any columns that could be to the right of it shifted left to take up area where Col2 normally is). The only way I can figure out how to do this is that I will have to generate all the JRXML at run-time, compile report and load data. But I would like to somehow take advantage of only using the compiled report if possible. Thanks, Jeff By: Jeff - jfsbf RE: Dynamically shift columns in compiled report 2005-10-05 07:24 Anybody got a comment on my original question? Teodor? This is a big issue with the project I am currently working on and anyone's ideas or solution will be greatly appreciated. By: Teodor Danciu - teodord RE: Dynamically shift columns in compiled rep 2005-10-05 07:59 Hi, You can later the X coordinate of elements and move columns around on your compiled report. Check the "alterdesign" sample provided to see how to get a hold of specific elements in the report template. But usually this use case scenario where users get a chance to design their reports at runtime would best fit dynamically building report template at runtime like shown in the "noxmldesign" sample provided. If you put the jdf-compiler.jar in the classpath of your application, there are no additional configurations to make for runtime compilation and you only lose about 200 milliseconds for each report compilation. But since users will probably won't like to be asked with every execution how would they want their reports to look like, you might end up implementing a way for those users to store their report templates once they design them the first time and be able to access predefined reports on subsequent runs. This is the perfect compromise solution since they will still have runtime generated report templates based on their options, but you'll still gain in performance since you are not going to recreate those with every run and load them from a temporary storage. I hope this helps. Teodor Link to comment Share on other sites More sharing options...
wiluspyder Posted November 3, 2006 Share Posted November 3, 2006 Teodor, I have a question for you.You mentioned that after creating the dynamic report users can save those as templates.Can you elaborate on this? Do you have any examples? I'm designing a report where users pick the column that they want to include in the report.So far I've read that this can be done via: 1. Crosstabs: but I haven't figured out how to do it. Is there an example where I can see how crosstabs are used to create a report with diff # of columns depending on the user's selection 2. Velocity & JR: I'd like to skip that approach as there is a fair bit of incorporating that into our framework 3. Use java to generate the xml just like in the noxmldesgin example. Let me know if there is another way to manage the issue of dynamic # of columns in a report.Thanks, JW Link to comment Share on other sites More sharing options...
Teodor Danciu Posted November 15, 2006 Share Posted November 15, 2006 Hi, I was talking about number 3.And the noxmldesign sample should show you how you can save to a file the report template you have built using the API. Thank you,Teodor Link to comment Share on other sites More sharing options...
lijf Posted November 21, 2006 Share Posted November 21, 2006 Hi,I wonder if there is a number 4 ? Check the "alterdesign" sample provided to see how to get a hold of specific elements in the report template. could i just add one column depending on those specific elements so i don't need to write the design from scratch using raw java code!Post edited by: lijf, at: 2006/11/21 07:59 Link to comment Share on other sites More sharing options...
suryaprakash26 Posted May 22, 2007 Share Posted May 22, 2007 hi, Could any please provide me the complete url for accessing the noxmldesign examples (/demo/samples/noxmldesign). thanks in advance,Surya Link to comment Share on other sites More sharing options...
suryaprakash26 Posted May 23, 2007 Share Posted May 23, 2007 hi, I am unable to locate the examples mentioned (noexmldesign). I need to refer to these as I have to show certain columns in my report dynamically. I was not able to find the above mentioned example in the reports samples, not sure if I am looking at the right location. Anyone who has used/referred to these, pls. point the exact location where the examples would be available. thanks in advance,surya Link to comment Share on other sites More sharing options...
singhipst Posted May 31, 2007 Share Posted May 31, 2007 Hi, Can any body please provide sample code to do that.Means i also wants to change coloumns according to user selection.How can i create a common template for my report so that using single template i can create diffterent type of report.Regards:Ritesh Kumar Link to comment Share on other sites More sharing options...
dkvidera Posted May 31, 2007 Share Posted May 31, 2007 We've had to deal with this too and have a few solutions. 1. If the number of columns is small and the same for all pages(data records) in the report, you can create the maximum number of column elements needed in the jrxml file and then set the unneeded ones to zero width and the needed ones to the correct width within the JasperReport object before sending it to the JasperFillManager. 2. If the number of columns is too cumbersome to create the maximum number of elements, you can create a subreport, load the jrxml, change the number of columns, compile the subreport, change the column element's width, and add it to the main report. Code:InputStream jasperIS = MyReport.class.getResourceAsStream("MySubreport.xml"«»); JasperDesign subDesign = JRXmlLoader.load(jasperIS); subDesign.setColumnCount(itemCount); int columnWidth = SUBREPORT_WIDTH / itemCount; subDesign.setColumnWidth(columnWidth); JasperReport subreport = JasperCompileManager.compileReport(subDesign); JRBand jb = subreport.getDetail(); JRElement je = jb.getElementByKey("theTextField"«»); je.setWidth(columnWidth); ... parameters.put("subreport", subreport); 3. If the number of columns changes for each page(data record) in the report, you will need to use a scriptlet. See my other post on "Changing report element properties in a scriptlet" for infor on how to do this. -doug Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now