views:

4124

answers:

6

Hi,

I have some Jasper reports which are displayed in HTML format. I would like the width of the columns in the HTML tables to automatically resize to fit the content of the widest cell (in that column), such that all the data is displayed.

Currently this does not happen because the HTML generated by Jasper specifies fixed widths for the <table> and some <td> elements, e.g.

<td style="width: 20px; height: 17px;">
  <span style="font-family: Arial; font-size: 11px;">foo-bar-baz@examp</span>
</td>

I can't simply remove all these width properties (using JavaScript), because (as shown in the HTML above) any data that would be hidden when using these widths is not even returned to the client-side

Cheers, Don

+2  A: 

While not perfect, you could flag the field to stretch with overflow. This would at least give you all the data. In your jrxml file it would be similar to:

<textField isStretchWithOverflow="true" hyperlinkType="None">
<reportElement style="Report Sub-Title" x="0" y="84" width="802" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["For the period ...]]></textFieldExpression>
</textField>

I'm afraid I don't know of any feature of Jasper reports that would allow the dynamic resizing of column widths - It is probably one of those things that makes sense for HTML but little sense for other output formats such as PDF.

Jamie Love
+1  A: 

Agree with Jamie Love. But I would apply his suggestion on the columnHeader tag, for the property to apply for the whole column.

al
+1  A: 

Have you tried using iReport. Its an IDE for writing JasperReports. It could make your life simpler.

Tom
A: 

Lo solucione !!!

En iReport (Spanish) existe una opción llamada *Estiramiento (textfield properties) y seleccione *Relativo al más alto de la banda

Saludos, Carlos Smake54

+2  A: 

(Carlos's answer, in English for those who do not speak Spanish):

The solution !!!

In iReport there is an option called "Stretch Type". Select "Relative to Band Height"

Cheers, Carlos Smake54

A: 

Carlos, se le aplica esto al reportElement? a mi no me funciono en PDF.

Maria