di.cao Posted June 3, 2013 Share Posted June 3, 2013 Hello everyone,I have a problem when I'm trying to use the input control to prefilter the reports:A table has two colomns, 'Count' and 'Date';the sample data here:----------------------------------------------------Count | Date | ----------------------------------------------------21 | May 10, 2013 | ----------------------------------------------------34 | May 11, 2013 | ----------------------------------------------------33 | May 12, 2013 | ----------------------------------------------------......---------------------------------------------------- Is there a way to get this by using the input control:when I click on the report, show me a dialog with three items('latest 7 days records','latest 30 days records','latest 90 days records'), after I make a selection, it will show me what I want?Thank you very much!D Link to comment Share on other sites More sharing options...
Solution Thomas Zimmer Posted June 3, 2013 Solution Share Posted June 3, 2013 you can achive this quite simple with the brand new cool DateRanges in jasperreports:1. Define a first parameter in your report, which gets the count of days you want to go back. In an input control in jasperserver (if you use that), you can build a combo box selection with a static value list, where the user sees 'latest 7 days records','latest 30 days records','latest 90 days records', but the passed value is an integer.2. Define a second parameter, which's type is "net.sf.jasperreports.types.date.RelativeDateRange" and initialize it with an expression, usinf the user's selection: "new net.sf.jasperreports.types.date.DateRangeBuilder("DAY-"+$P{selector}).toDateRange()"Then you can use the second parameter, e.g. in a sql statement by typing ".... WHERE date_colum >= $P{param2}.getStartDate()"See the attached report to make it more clearly :-)Cheers, Thomas http://www.thomaszimmer.net Link to comment Share on other sites More sharing options...
di.cao Posted June 3, 2013 Author Share Posted June 3, 2013 Thank you so much! Very helpful! -- D Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now