Jump to content
We've recently updated our Privacy Statement, available here ×

print a group header in a new column


allahu-akbar

Recommended Posts

Hello,

I've just found out about grouping elements in a report and it works pretty well for my report, when I only have one column to display everything: I have two groups, and they print well (I want to start a new page when the first group changes and to just gather all the results under a single element in the second group when that group changes. I can attach a renderd PDF if necessary).

The thing is, I've set the report to use two columns and it simply won't show the group headers on the second column. It does display the results, but no headers. I've attached a sample image, in case you want more information.

Everything works, just that there are no headers in the second column. Any way I could force the headers to be printed on the second column ? I've checked the group properties, but the only property that seems useful in this case is minHeightToStartNewPage, which, only refers to a page, not a column. The rest of the properties are just to specify an action when the group breaks, while I only look to continue displaying the current group on the next column. Has anyone had this problem before?

Thank you for any responses.

A.D.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Hello,

What I want is that the headers for each group be reprinted on the second column. The first group is the one based on the category field, and contains the first colored band of elements (static texts), and te second group is set on the name of each subelement of the category group, and this new element also has subelements (the category subelement has it's name on the brighter coloured band, and then follow its sublements).

The problem is that when I fill the report with lots of data for a category subelement, it just continues on the second column, without printing the headers for either group defined, like in the first image I attached. Also I'm using XML as a datasource. I've attached the code in case it will be of any help.

I've set both reprint headers and keep together properties, so that the first groups starts in a new page, and the second group always reprints its headers when a new element comes in. This is done on a new page (the headers appear for a new column on a new page) but I looking to have the headers reprinted on the second column in the current page.

Thanks for taking a look.

A.D.

Code:
<?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="new_template" columnCount="2" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="381" leftMargin="40" rightMargin="40" topMargin="20" bottomMargin="20">	<property name="ireport.zoom" value="1.5"/>	<property name="ireport.x" value="0"/>	<property name="ireport.y" value="0"/>	<field name="category" class="java.lang.String">		<fieldDescription><![CDATA[category]]></fieldDescription>	</field>	<field name="name" class="java.lang.String">		<fieldDescription><![CDATA[name]]></fieldDescription>	</field>	<field name="elementName" class="java.lang.String">		<fieldDescription><![CDATA[elementName]]></fieldDescription>	</field>	<field name="elementType" class="java.lang.String">		<fieldDescription><![CDATA[elementType]]></fieldDescription>	</field>	<field name="elementPreference" class="java.lang.String">		<fieldDescription><![CDATA[elementPreference]]></fieldDescription>	</field>	<group name="elementCategory" isStartNewPage="true" isReprintHeaderOnEachPage="true" keepTogether="true">		<groupExpression><![CDATA[$F{category}]]></groupExpression>		<groupHeader>			<band height="40">				<textField>					<reportElement x="0" y="0" width="100" height="20"/>					<textElement/>					<textFieldExpression class="java.lang.String"><![CDATA[$F{category}]]></textFieldExpression>				</textField>				<staticText>					<reportElement mode="Opaque" x="0" y="20" width="169" height="20" backcolor="#99B4D1"/>					<textElement/>					<text><![CDATA[]]></text>				</staticText>				<staticText>					<reportElement mode="Opaque" x="169" y="20" width="100" height="20" backcolor="#99B4D1"/>					<textElement/>					<text><![CDATA[sector]]></text>				</staticText>				<staticText>					<reportElement mode="Opaque" x="269" y="20" width="111" height="20" backcolor="#99B4D1"/>					<textElement/>					<text><![CDATA[Preferrence]]></text>				</staticText>			</band>		</groupHeader>	</group>	<group name="elementName" isReprintHeaderOnEachPage="true" keepTogether="true">		<groupExpression><![CDATA[$F{name}]]></groupExpression>		<groupHeader>			<band height="20">				<textField>					<reportElement mode="Opaque" x="0" y="0" width="380" height="20" backcolor="#CCCCFF"/>					<textElement/>					<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>				</textField>			</band>		</groupHeader>	</group>	<background>		<band splitType="Stretch"/>	</background>	<pageHeader>		<band height="50">			<staticText>				<reportElement x="0" y="19" width="762" height="30"/>				<textElement>					<font fontName="SansSerif" size="16"/>				</textElement>				<text><![CDATA[Title]]></text>			</staticText>			<line>				<reportElement x="0" y="49" width="762" height="1"/>			</line>		</band>	</pageHeader>	<columnHeader>		<band/>	</columnHeader>	<detail>		<band height="20" splitType="Stretch">			<textField>				<reportElement x="169" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{elementType}]]></textFieldExpression>			</textField>			<textField>				<reportElement x="269" y="0" width="111" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{elementPreference}]]></textFieldExpression>			</textField>			<textField>				<reportElement x="0" y="0" width="169" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{elementName}]]></textFieldExpression>			</textField>		</band>	</detail>	<pageFooter>		<band height="54" splitType="Stretch">			<textField>				<reportElement x="701" y="34" width="61" height="20"/>				<textElement textAlignment="Right"/>				<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>			</textField>		</band>	</pageFooter></jasperReport>
Link to comment
Share on other sites

  • 3 weeks later...
  • 9 months later...

Yes, I do this all the time, because I want my column headers to be right before the data in the detail record that it's actually labelling, so what I do whenever I use groups is the following:

1. For each group, I select the "Reprint headers" checkbox so the current group header(s) repeat at the top of every page.  If I have multiple levels of group headers, I might make the top level one also start on a new page.

2. For the lowest-level group header (the one that will always print just before the first detail record), I make sure the band height is enough to contain a description of what group I'm in and some column header information.  Usually for me this means I make the lowest-level group header have a band height of 40.  I usually start my column-style reports with a template that has a blue Frame element already in the Column Header band, so I usually just cut and paste that from the Column Header band to my lowest level of Group Header, and then I drag it so the top of the Frame is at 20.  Then I delete the actual Column Header band, because I no longer have any need for it.  I'll also set the "Min Height to Startt New Page" property for the group header to 80 or something like that to try to make sure that at least the group header (40) and one or two detail records (20 each) will fit on the page, otherwise I jump to a new page to start the group.

3. I like to make a distinction between when a group changes vs. when the header is re-printing at the top of the page, so I usually create two overlapping text fields at the top left of each group header band.  They both contain the description of the group like $F{DepartmentName}, but one of them I put in bold and give a Print When condition of $V{DeptGroup_COUNT}==0 (or whatever the name is of the count variable that iReport automatically creates for you when you create a group).  The second version I usually add   +" (continued)" to the Text Field Expression, I don't make it bold, and I give a Print When condition of $V{DeptGroup_COUNT}>0.  Finally, I'm a big proponent of PDF bookmarks, so I usually right click the first version of the group description (the one I'm printing in bold when the group count is 0) and select "Hyperlink", set the "Anchor Name Expression" to $F{DepartmentName}, set Bookmark Level to 1 (if this is the top level group header--use 2 for the next lower level, etc.) and I leave the other settings alone.  I usually also create a Text Field in my Summary section that says "Total" and create a level 1 hyperlink on that as well so it's easy to jump right to the summary.  It's nice that the overlapping fields with mutually exclusive Print When conditions that I originally created so that one version could be in bold while the other version could say " (continued)" on the end actually also proved to be the key to making sure I could create a PDF bookmark that only comes into play when the group changes and not when the group header is being repeated.

I think the answer to your question is really just the part of a sentence I put in bold, but I hope the other techniques prove useful to you and others as well.  I really like the consumer of the report to always know at the top of every page where they are in the report, but I don't like to separate column header labels from the data they are labelling, and I like to help a PDF user navigate the report easily.  All these goals are met using these techniques.

Carl

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...