iReport

I played about with iReport 3.5.1 and its new list component, it’s rather good. Here’s what I did.

I have a report that gives food sales within a date range and groups them by the food group (Meat, Vegetables and cake, say). One thing I’ve wanted to do for a while was have the total for each group in the summary at the end of the report. To save you looking through to find page 12 and the total for a group that may only have a few items in it. You could do this with complicated “if, then” statements in report fields or a fiddly subreport, but now you can use the List.

First drag the list component to the summary band. This causes an expected rectangle to appear on the page, and a “Component” stub to appear in the report inspector, but this isn’t where you need to start, for a new section has been created in the Report Inspector called dataset1. Its underneath the scriptlets section (with the coffee mug icon, see it?)

Clicking the + to expand the dataset1 tree brings up the subsections Parameters, Fields, Variables and Groups. The first three we are familiar with and gives us the first clue we are working on a report within a report.

Right clicking on the dataset1 stub brings up a context menu. In it we can see that equally familiar option “Edit Query” option. Clicking on it takes us to the Report Query window and we can Query to our hearts content.

Just like the main report the fields are automatically generated for us, so for us who use SQL we can merrily SELECT some,columns FROM a.table

Back in the dataset1 stub the sub-entry Fields has some things we can drag into our Component.

Now, scooting down the the summary section and right clicking the Component brings us up a context menu with “Edit list datasource” at the top. Sources for data are vital if you don’t want boring nulls everywhere. Clicking it brings up a window which tells us which dataset we are using (dataset1) and three tabs, the first two are parameters which we’re not using so lets skip right on to the clumsily named “Connection/Datasource exp” (I can’t read exp without thinking experience, sorry)

Its default is set to “Use datasource expression” which I’m guessing means we can create a datasource link to an entirely separate DB to the one the main report is using, pretty awesome stuff but overkill for what I want. The report already has a datasource and I want to use that. Clicking on the combo box gives us the option of “Use connection expression” which does exactly what I want so lets use that.

Now we can run the report. Yes, thats all there is to it. Passing parameters to a list from the main report is as simple as setting up parameters in dataset1 and it’s query, then matching them up using the Components “Edit list datasource” and that first tab we saw.

Easy as eating pancakes.