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
1 Answer:
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
Attachment | Size |
---|---|
![]() | 1.44 KB |
Thank you so much! Very helpful! -- D