Saturday, March 5, 2016

Jasper Report: How to pass parameters to crosstab



In order to pass parameters into crosstab, first of all, we need to create parameters related in main report. Below is the example:




























After that, we need to create another 2 parameters in crosstab (crosstab parameters). Below is the example:

























                          Please ensure that all of the parameters in the main report and in crosstab section are using the same name and class. Below is the example:













Nevertheless, if you are using Jaspersoft Studio Community version, most of the time your IDE will have problem creating crosstab parameters. Therefore, alternatively you can create crosstab parameters in XML source and then assign crosstab parameters value with main report parameters value using <parameterValueExpression> tag. Below is the example:











                                           
Finally, compile and then run your report.

That’s all.

3 comments:

  1. Nice. But this example doesn't show, how to pass parameter to crosstab. This pass parameter value only to a crosstab sub-dataset. How can you use this parameter value in crosstab layout? Or as a hyperlink parameter? I have found the way, using Crosstab parameters, but JasperSoft Studio doesn't allow me to add new parameter and set parameter mapping. Have you some idea how to set it directly in XML definition?

    Thank you for response.

    Tomas Nemecek (Czech Republic)

    ReplyDelete
    Replies
    1. So much later, but...

      The example shown above works well.

      That is what I did:

      1) Create a parameter in the main dataset of main report;

      2) Create a parameter in the crosstab (not in the subdataset of crosstab) with the same type and the value expression referencing the parameter created before;

      3) Just referenced the parameter inside the crosstab layout.

      With these steps, it worked well

      Delete
  2. This works well.

    Thanks a lot.

    JM

    ReplyDelete