How to show data in multiple columns in report - jasper-reports

Requirement:
I have a table in DB as below:
COP_MASTER
-----------------
CopDuty CopName
Duty1 Alpha1
Duty2 Alpha2
Duty1 Alpha3
Duty1 Alpha4
Duty2 Alpha5
Using iReport I need to prepare a report where the report looks like this:
CopDuty CopName
Duty1 Alpha1 Aplpha3 Alpha4
Duty2 Alpha2 Aplha5
Here the list of CopNames grows horizontally (or in a simpler terms the columns are dynamic).
I have already tried using subReport and inside the subReport's detail band a List element where the PrintOrder for the list element is kept "Horizontal". But the list grows vertically and not horizontally.
Any advice or help?

Prepare an independent report with the copName as a field to be displayed.
Make the printOrder properties available in the report properties tab as "Horizontal"
Change the Columns value:n (where n>1)
Go the main report and add the subreport element with the choice "Just add the subreport element".
Go to the Properties tab of the subreport element do the following changes as below:
Subreport Expression: $P{SUBREPORT_DIR}+"CopSubReportFileName.jasper"
DataSourceExpression: new net.sf.jasperreportsengine.data.JRBeanCollectionDatasource($F{cops})
Here we have to note that if the "cops" is a BO associated in the "Duty" BO then the above solution is just fine. But if it is to be tested through DB conn directly then the "dutyId" must be passed as report input parameter to the subreport for the corresponding copNames to be fetched and printed.

Related

Passing values from main report to subreport in JasperReports

I have a simple select sql query with 2 parameters that I want it to be in my query text in main report. It returns about 100 values that I want to put in 10 subreports (10 values per subreport). On main report I need to display only one parameter. All the values from query I need to be in subreports. How do I pass them?
Connection to database is returned to me from application, parameter values also. I'm using iReport 4.7.0.
Parameters are attached to the dataset, if you expand the dataset itself, you'll find a section there for parameters, just like in your main report.
You'll need to link the parameters together though, using the connection properties where you're actually using the dataset, eg, in a chart or a table. For example, in the table, you go to the dataset tab of the properties pane, and click on the parameters button to map the parameters between your main report and your sub dataset.
More here.

JasperReports / iReport Designer: Can i show a band conditionally?

I have created a report as follow:
Multiple detail band
each detail band contains 1 table. Each table is linked to 1 dataset.
Can I hide the detail band whenever the result set of the query returns Empty set (no result found)?
how can I achieve this?
In the "Properties" of each Detail band you have an option called "Print When Expression" there you can place logic that evaluates to boolean.
When you fill it with your logic and it returns true this detail band is printed.
So, you will need to have the information if the table will be filled in advance and cannot address the dataset within.
If your datasets are too different to do this, you should overwrite the Dataset for the main report with a custom one that gathers the information and sets the fields appropriately.

Combine all SSRS reports in the Grid into one report

It should be very simple and should employ multi-value parameters , but not able to figure out how ? This report takes parameters from the GridView I have a gridview in an asp.net web page which has print button for every row to print this report for that row.
Now, there are as many reports as there are rows in the grid.---[This part is done]
So,how about combining all these reports into one single report
You can add a subreport for each one of you reports.
You just create a new report and start inserting subreports in each row.
Check this documentation:
http://msdn.microsoft.com/en-us/library/dd220581.aspx
Here's an example for you:
1 - Create a new report. You can then add a tablix to it, in case you have more info, which is the case in my example. Just don't forget to add a dataset to that tablix if that's your case.
This is how it would look
Each gray line is a subreport.
2 - To insert a subreport just right-click a cell and go to Insert > Subreport
3 - Right-click your subreport, select Subreport Properties and choose your report from the drop-down menu:
4 - You can then set the parameters your subreport will receive:
Case 2: if you don't need a tablix for aditional info, just repeat the same process in a Rectangle.
UPDATE
As I said in my comment, here's one report in which I do exactly what you want:
As you can see the subreports are part of the main report's body that has other data.
I need to repeat these subreports for each record and that's how it is done.
Here you can see the Id being passed as parameter to my subreport:
From what I understood, that's what you want. That way for each record its current Id would be passed to the report. Generating a report with that "dynamic" parameter you mentioned.

Hide space between elements of a report

I have one report with various subreports. These subreports are within a table cell. When the subreport doesn't have any data available, I hide the components (tables, textbox, charts) in that subreport. However, this creates some blank space and I need to eliminate this space.
I already used the properties ConsumeContainerWhiteSpace and KeepTogether, but the blank space is still there.
Any suggestions to remove the blank space?
To hide or show an entire row based on another reports results will be difficult, if not impossible. You will need to get this data in your parent report somehow.
I would create a cut down version of your subreport's query that returns row count for every subreport, but within the parent report. Might look like this:
UserID RecordCount
Abby 3
Bob 0
Carl 1
If you are using SSRS 2008r2 you can then use a lookup function to set row visibility. For example the row visibility expression might be
=IIF(Lookup(Fields!UserID.Value,
Fields!UserID.Value,
Fields!RecordCount.Value,
"LookupDatasetName") > 0,
false,
true)
If an earlier version of SSRS, then join that dataset into the dataset for your table.

Displaying tables below each other in JasperReports

I have to create a report where several tables are diplayed below each other. Each table gets its data from a SubDataset and contains none, one or more rows.
For the first version of the report, I've simply ignored the possibility of a table having no rows and put all tables below each other, each with the height of 1 row. The idea was, that if there is more than one row, the table will grow in height, which seems to work fine. I've given the first table a fixed position and set all subsequent ones to float. In iReport it looks like this:
But when I create a report, only the first table is at the expected position. The rest is displayed too low and overlaps:
Any idea how to fix this? I can't use subreports, because the report is stored in a database so I can't reference other reports. Is there maybe another alternative to subreports or tables?
You have the "Position Type" property set to "Fix Relative to Top". Change it to "Float".
Try looking into using subreports. I do create table followed by another (datasource is XML).
create subreport using xPath
Use Data Source Expression property of the subreport to set the datasource for subreport
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/FUND_STATEMENT/FUNDS/FUND")