A question about input control of Jasper5.1

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

 

di.cao's picture
4
Joined: Jun 3 2013 - 9:44am
Last seen: 9 years 8 months ago

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 

http://www.thomaszimmer.net

Attachments: 
AttachmentSize
Binary Data report4.jrxml1.44 KB
Thomas Zimmer's picture
Joined: Oct 2 2012 - 1:35am
Last seen: 1 month 4 days ago

Thank you so much! Very helpful! -- D

di.cao - 10 years 3 months ago
Feedback
randomness