开发者

Change size/position of Jasper Reports columns

开发者 https://www.devze.com 2023-02-05 06:05 出处:网络
In Jasper Reports, is it possible to dynamically change the width or position of a column based on certain criteria?

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 rep开发者_如何转开发ort 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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号