Showing posts with label JasperReports. Show all posts
Showing posts with label JasperReports. Show all posts

Tuesday, July 31, 2007

Custom sort of rows and columns without writing comparator

When doing JasperReports, I am often asked to sort the rows and columns in a particular ways other than alphabetical. JasperReports does support customized comparators for sorting. But I found it quite complicated to implement and not very easy to update in the future. Today I figured out a trick that can do arbitrary sorting easily.

In my sql statement, I concatenate the sequence number and the actually value together, for example, '01Banana', '02Orange', '03Apple'. Then in my report, I chop off the sequence number before displaying it, such as $F{field}.subString(2).

This trick works fine for small number of values.

Tuesday, October 31, 2006

When doing JasperReports yesterday, I encoutered a weird problem. I have some text fields that holds long strings, so the text has to be wrapped. So I set the text fields to stretch with overflow. It worked fine in iReports 1.2.6. But after deploying it to a web application (Centric CRM), some text fields got the last line cut off, just the last line. And this is not happening on all fields in a page, just some.

I tried different versions of JasperReports and Lowagie iText libraries without any luck. Eventually I figured it out. I have the text fields height set to 18 pixels and my detail band set to 20 pixels so I can get a little padding on top and bottom. Somehow these little padding confused JasperReports. After setting all textfields and band to 20 pixels height, everything worked fine. To archieve the little padding, I set the padding in the Border tab in Properties dialog.

Long story short: When doing JasperReports, if you get the last line cut off when setting Textfield to stretch with overflow, check the text field height and band height. It may help.