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

Using hyperlink on a field for sorting data in JasperReport


peter_tonev
Go to solution Solved by peter_tonev,

Recommended Posts

Hello community,

 

I need to sort the content in my report based on clicking the data header (i.e. some sort of hyperlink). I found out that Jasper has the sort component, but it is rendered as a seperate element (an up / down arrow) which you can place anywhere. Is there a way to define a hyperlink on data field headers (or column headers) and then when clicking on it to sort ascending (by second click - descending) the data based on the underlying data field, instead of going to some reference mark or executing another report?

I found a workaround on this - first click executes an ascending sorted report in the same page frame, second click executes a descending sorted report. But this is a clumsy soution for I have more columns and hence I have to create two reports for each column which is a no go. Furthermore, this way the data set is recreated each time and what I only need is just sort the already fetched data.

 

Thanks and regards,

Peter

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution

OK, I figured it out myself, here a solution for the interested:

Pull a sort component from the pallete, define the column (set) by which it should sort, set "opaque" property off, set evaluation to "Now", align the sort component to the right, make it a little bit wider as your header, put it over the header so that the right aligned arrow does not overlap with the text, done.

Now when you deploy the report on the JRS and run it, you will get a hyperlink over your text (column header); click it once - report content gets sorted ascending by the ccolumn (set) defined and an up-arrow is rendered, second click - it gets sorted descending and a down-arrow is represeted, third click - sort is removed (the data set reappears in the initial sort order) and no arrow is showing.

 

Cheers, Peter

 

Link to comment
Share on other sites

  • 2 years later...

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...