Jasper Report group subreports using columns - jasper-reports

I have a master report (using iReport 5.0.4) with a subreport that uses grouping by a field called "Group Number" (sorry, but that is the actual column name).
My report works fine when there are more than one group, but it generates each group result scrolling down the page vertically.
I would like to be able to have each group go across vertically, but when I tried using columns, it simply forces each group's data into columns, and not the entire group 1, followed by group 2 in the next column, etc.
There can be up to 8 groups, so I was hoping not to have to create 8 individual sub-subreports with a "print when" expression to show/hide them.
Can anyone tell me if this should be possible?
Thanks,
Mitch

I think making subreports is the easiest and obvious way. But if you want to make it in other way, I can only suggest to use scriptlet, and form dataset manually (Transpose it).
Another suggestion is when you generating report directly from database (i.e. passing connection into jasper) you can modify query and transpose the data (PIVOT table).
Anyway provide more info about your case. I will try to help you.

Related

Prevent grouping column header in JasperReports

i want to make an Crosstab Template for my data.
For each value there is a timestamp, a location and the name of the device from which i get the value. So i am giving a list of values via Java and a JRBeanCollectionDataSource to my report, for the example below this would be 9 values while each of them has 3 additional parameters to place it on the right column/place in the crosstab.
When i give this sort of data to my Jasper Report with a Crosstab (Crosstab is needed cause i don't know how many rows and columns my report will have) in it, Jasper orders/groups the columns and the output looks like this:
But what i want is to show the data in the sequence i give them to my report, for example:
I am using Java to fill my report with a JRBeanCollectionDataSource and a self defined DataSource (this works perfect, i am working with this method for months).
Is there any way this kind of column grouping could be prevented? (i have a working crosstab template but i am not able to find the propertie with the help of i can solve my problem)
Hope you people can help me.
Have you tried to tell the crosstab that your data ir already sorted?
http://jasperreports.sourceforge.net/schema.reference.html#crosstabDataset
Click the crosstab element, in the Dataset Tab, mark "Data Pre Sorted".

Report vertical layout

I have existing report w/ "groups" for Total/Directs/Warehouse/Credits that span horizontally. I need to now stack these groupings vertically. What is the best way to do this in CR? I am used to SSRS, Excel, PowerBI, etc. Crystal Reports is much less intuitive than those tools.
Do I need some kind of funky nested groups? Sub reports? How should we approach this? We assumed it would be a pretty simple formatting/layout change. But it looks like it's actually quite complex to do this.
Original:
How it needs to be re-worked:
If the entire table you're showing is in a Footer, you can just add 3 new footer sections and duplicate the table in each (removing any columns you don't need.) Just right click the relevant section and Insert Section Below.
Otherwise you'll need to use subreports. But since you have the columns already configured, all you really have to do is:
Save 4 subreports, Total, Directs, Warehouse, and Credits. (Just save a copy of your existing report, and delete everything that doesn't need to show up in Total. Rinse and repeat.)
Import each and add the parameters as subreport links
Give them each their own section

Crystal Report with multiple datasources

I am working on a crystal report like in the sample image. it has some limited attributes and some attributes that will be repeated. like item id will be repeated for each item and invoice id will be only one in the whole invoice. I am trying to use two different tables one for repeating elements and one for single time elements.
I am facing problem in setting the datasource of the crystal report. how can I set it so that it may fetch data for repeated elements from datatable one and other from datatable two.
Or if you know any other approach for such problem please share.
Problem Solved.
We can use as many datasources as we want. We just need to add them through database expert options.
besides while giving it actual data we can do that like this:
objRpt.Database.Tables[0].SetDataSource(list_of_objects_of_data_sources);
objRpt.Database.Tables[1].SetDataSource(list_of_objects_of_data_sources2);
this also shows that we can provide data to crystal report through list of obects instead of datatables. we just need to set the references in the database expert as those class objects.
like in the figure

Crystal Reports: Cross-Tab Column Arrangements

I am looking for a way out in cross tab, so that if the columns exceed in cross tab, they shouldnt go on next page..rather a new cross-tab should repeat after the first one.
For example, two columns are displayed in a cross tab :
Now if a new column is added, and assuming that it could not be accomodated within the given page width limit, it will go to a page next to it in CR by default.
But in my report it is required to be shown below the first cross tab (and not on next page), which will look as follows:
Please do suggest me if there's a way out :)
Thanks in advance
Your question is perfectly reasonable, but I'm pretty sure that in CR-XI, there is no automatic way to do this. I recommend skipping the cross-tab designer completely and just making your own:
Make a new CR using a placeholder table that has exactly 1 record.
In this CR, suppress everything but the details section. Add a new details section so you will have Da and Db.
In Da, add a subreport. Use your real datasource and add Column1 and Column2.
In Db, add a subreport. Use your real datasource and add Column3 and Column4.
I don't have time to test this, but I think it will display all the columns as you requested.
(Instead of step 1, you can probably use a placegrouper group in your report that only has 1 group. Then, when you add the subreports, make sure to not add any links to the main report.)
Edit
A dynamic number of columns makes this request much more difficult to do in Crystal.
Maybe you could autogenerate the entire report from a script. I couldn't help you with that, but I'm sure someone else on StackOverflow will.
You can use MS Excel to achieve something similar. Use MS Access or something similar to set up a crosstab of your data. Open a new Excel workbook and import your crosstabbed datasource using Data->Import External Data->Import Data (this imports the entire table, regardless of number of rows). In Page Setup, change settings to Fit to (blank) pages wide by 1 pages tall. You can format the data however you like and the format will be retained. This Excel method will squeeze all your columns into a 1-page wide area. It's not quite what you're asking for, but it will work.
The number of columns may be dynamic, but do you know what the field names could be? For example, your columns include 0-50 US States, then you know what the column names will be, just not which ones or how many. If this is your situation, then use my first suggestion (check off the suppress if blank options to hide unneeded subreports). It won't be pretty (alot of white space), but it can get the job done.
A possible solution can be a multi column report. But it can be difficult to make the row labels and values in the same line.
If you can create an additional row grouping then you have the solution that you want. For example if your columns have number like in your sample. Then you can add a formula like:
columnId \ 2

Displaying a Tree Structure in Crystal Reports

Does anyone know of a way to represent a tree structure in Crystal Reports?
My big issue is that I don't know the depth of the tree. It is represented in a database table with a simple "childId -> parentId" relationship.
A perfect example would be to open Windows Explorer, and look at the directory tree on the left side. If anyone knows a way to represent that tree, then it'll work for what I need to do too.
My initial attempts have been:
1) to programatically (in C#) add Groups to the report. Unfortunately, you can't create a new instance of the Group class and add it to the Groups collection.
2) recursively nest the same report into itself for each level. In other words:
mainReport
subReport
subReport
subReport
subReport
subReport
subReport
etc...
Unfortunately, SubReports can't contain SubReports.
I really don't want to just add X number of groups into a report and hide the ones I don't need, because I'd have to add a fixed number of nested groups, but technically the data design can support an infinite depth, even though in practice we see up to about 5 levels of depth.
So, any other ideas?
Crystal XI added hierarchical grouping. You'll find this under the Reports menu. I put together a quick org chart report with n-level depth using this. The database table is like:
id
name
managerId
In the Crystal Report, you select these columns, group by id. Then under "Hierarchical Grouping options" menu under Reports, check off "Group Data Hierarchically", parent Id managerId, and indent appropriately.
The output is like the tree you described in Explorer.