How to display custom number of elements horizontally?

I want to display elements horizontally (in one line). I present this problem as a table with a single row and a dynamic number of columns. Each cell in this table contains the same subheading, but with a different data source.

At first, I tried to combine a list of components and a subreport. But it turned out that the list component does not support horizontal layout. Instead, I read somewhere to use a crosstab. But when I try to insert a subreport into the measurement cell, iReport displays a message that I cannot do. So what can I do?

+4
source share
2 answers

Based on your previous comment, I would say that printing a list of elements horizontally is not so difficult. The List component is basically a subreport. That way, you can also create your own List component, which prints a list of items horizontally. All you need to do is create a new report without any fields, set its “ Print Order ” to “ Horizontal ” and set the number of columns according to your requirements. Then you can insert this report as a subordinate into some main report and print elements horizontally.

According to your requirements, you can adjust the size of the report and text field accordingly. Here is a screenshot for this report that I created:

enter image description here

And here is a sample jrxml document that I created:

<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report name" columnCount="5" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="119" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <background> <band splitType="Stretch"/> </background> <title> <band splitType="Stretch"/> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnHeader> <band splitType="Stretch"/> </columnHeader> <detail> <band height="20" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="100" height="20"/> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{field}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band splitType="Stretch"/> </pageFooter> <summary> <band splitType="Stretch"/> </summary> </jasperReport> 
+5
source

@bchetty: Sorry I decided to respond, not comment, because I don't have enough reputation to do this. The solution you submitted works fine, but leaves the layout of the report pretty Ok. I had a familiar requirement when I saved the size of the columns as 20, but then I can never predict that it will not cross 20 in some query. Again, if only three values ​​are retrieved from the query for columns, the remaining column spaces remain empty and do not provide a good layout for the generated report.

I read in iReport the final reference that if List is used as an auxiliary report and printOrder is “horizontal”, we can get the effect of dynamic columns. But I believe that this is just an “effect” and not dynamic columns, since the size of the columns should be fixed at a value greater than 1.

I am at the end trying to achieve this, but I think I may have to refuse. Crosstab cannot come to the rescue as it is limited to two row groups and two column groups. But there are other fields in the report that should also be printed along with dynamic columns. Print horizontal sub-report data

0
source

Source: https://habr.com/ru/post/1391432/


All Articles