Jump to content
We've recently updated our Privacy Statement, available here ×

Sort based on parameter


cckozie

Recommended Posts

 I'm running iReport 3.7.1 and MySQL 5.1. I'm attempting to have the sort order set based on a parameter but can't get it to work. I've tried these 3 methods: 1) Use the parameter name in the ORDER BY clause. 2) Add the parameter to the SELECT clause with an alias and reference the alias in the ORDER BY clause. 3) Same as 2, but reference the alias in the Sort order (memory sort) dialog. In each case the report runs, but the records appear in the same order as if there were no ORDER BY or Sort order specified. If I paste the query for method 2 directly in the MySQL Query Browser or OpenOffice it does work properly. Any ideas?

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

 

In the query, where you use a parameter as sql chunk (and not as value parameter), use the special syntax $P!{param}

In 3.7.5 JasperReports has introduced the ability to sort records using variables, so just create a variable with an expression that uses your parameter, i.e.

My_order  (type String; calc: Nothing)

exp:    $P{my_param} == 1 ? $F{field1} : $F{field2}

Giulio

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...