sim
sim

Reputation: 3602

Change size/position of Jasper Reports columns

In Jasper Reports, is it possible to dynamically change the width or position of a column based on certain criteria?

For example, we have a report that contains the following columns:

ID | Name | Course | Status |

Now, there is an option to allow the report to only display a person's ID, as opposed to the ID and Name. If we make the name column null, we end up with a huge empty gap between the ID and Course columns:

ID |_____| Course | Status

Is it possible to programmatically reposition the remaining columns, so that they all shift up to the be next to the ID column?

Upvotes: 3

Views: 3526

Answers (1)

yshalbar
yshalbar

Reputation: 1473

We had the same problem, and didn't find a solution, just ugly workarounds.

We started with a simple solution of having two designs, when we had two options.

When more options arrived, this became impossible to maintain. We now use a dynamic structure:

$P{field_name1} | $P{field_name2} 
------
$F{value1} | $P{value2} ...

We pass the field names as parameters, and use a dynamic data-source. We don't show the last, empty columns if exist. Note that we needed to dynamic query and populate the data-source in code, so this may not be a viable solution.

Another option you have is you create the Jasper Design in code (We also do this, in another scenario) - we load a jrxml template, and then dynamically add bands and items as needed.

JasperDesign jasperDesign = JRXmlLoader.load(myJrxml);

Upvotes: 1

Related Questions