Column

DynamicReports has an ability to display data in a multi-column layout. There is no limit in number of columns added to the report, only keep in mind that the more columns you add to the report, the less space will be available for each column.
All columns automatically fit the available page width.
Column The picture above shows what is a column and how it is divided.
Configuration options of a column title

methoddescription
setTitle(String title),
setTitle(DRIExpression<?> titleExpression)
Sets the column title
setTitleStyle(StyleBuilder titleStyle) Sets the column title style
setTitleRows(Integer rows),
setTitleFixedRows(Integer rows),
setTitleMinRows(Integer rows)
This method is used to define the height of a column title. The height is set to the rows multiplied by height of the font
setTitleHeight(Integer height),
setTitleFixedHeight(Integer height),
setTitleMinHeight(Integer height)
Sets the height of a column title

Configuration options of column values

methoddescription
setStyle(StyleBuilder style) Sets the column value style
setPrintWhenExpression(DRIExpression<Boolean> printWhenExpression) Sets the print when expression. The expression must be a type of Boolean and it decides whether or not a column value will be printed
setRows(Integer rows),
setFixedRows(Integer rows),
setMinRows(Integer rows)
This method is used to define the height of a column value. The height is set to the rows multiplied by height of the font
setHeight(Integer height),
setFixedHeight(Integer height),
setMinHeight(Integer height)
Sets the height of a column value
setPrintRepeatedDetailValues(Boolean printRepeatedDetailValues) Specifies whether or not print a value if the value is the same as the previous value
setHorizontalAlignment(HorizontalAlignment horizontalAlignment) Sets the column value horizontal alignment
setPattern(String pattern),
setPattern(DRIExpression<String> patternExpression)
Sets the column value format pattern
setValueFormatter(DRIValueFormatter<?, ? super U> valueFormatter) Sets the column value format expression
setHyperLink(HyperLinkBuilder hyperLink) Sets the column value hyperlink
setStretchWithOverflow(Boolean stretchWithOverflow)
addProperty(DRIPropertyExpression propertyExpression),
addProperty(String name, DRIExpression<String> valueExpression),
addProperty(String name, String value)
Adds a jasper property to the column value

Configuration options of a column

methoddescription
setColumns(Integer columns),
setFixedColumns(Integer columns),
setMinColumns(Integer columns)
This method is used to define the width of a column. The width is set to the columns multiplied by width of the character m for the used font
setWidth(Integer width),
setFixedWidth(Integer width),
setMinWidth(Integer width)
Sets the width of a column

Examples
Column examples

Text column

It is represented by a TextColumnBuilder instance and it is used to show values from the data source.
Builders

methoddescription
col.column(String fieldName, Class<T> valueClass),
col.column(String title, String fieldName, Class<T> valueClass)
Creates a new column
- title (optional) - the column title
- fieldName - the name of the field
- valueClass - the field value class
col.column(String fieldName, DRIDataType<? super T, T> dataType),
col.column(String title, String fieldName, DRIDataType<? super T, T> dataType)
Creates a new column
- title (optional) - the column title
- fieldName - the name of the field
- dataType - the field data type
col.column(FieldBuilder<T> field),
col.column(String title, FieldBuilder<T> field)
Creates a new column
- title (optional) - the column title
- field - the field definition
columnInstance.add(TextColumnBuilder<? extends Number> column),
columnInstance.add(Number number)
Creates a new column by adding a value or a column value to the columnInstance column
columnInstance.subtract(TextColumnBuilder<? extends Number> column),
columnInstance.subtract(Number number)
Creates a new column by subtracting a value or a column value from the columnInstance column
columnInstance.multiply(TextColumnBuilder<? extends Number> column),
columnInstance.multiply(Number number)
Creates a new column by multiplying the columnInstance column with a value or a column value
columnInstance.divide(int scale, TextColumnBuilder<? extends Number> column),
columnInstance.divide(int scale, Number number)
Creates a new column by dividing the columnInstance column with a value or a column value

Examples
Quick usage:

report()  
  .columns(  
    col.column("Item", "item", type.stringType()),  
    col.column("Quantity", "quantity", type.integerType()))
  .setDataSource(...) 
 
Another example: ColumnDataTypesReport

Expression column

It is represented by a TextColumnBuilder instance and the displayed values are defined in an expression.
Builders

methoddescription
col.column(DRIExpression<T> expression),
col.column(String title, DRIExpression<T> expression)
Creates a new expression column
- title (optional) - the column title
- expression - the value expression

Examples
Quick usage:

report()
  .columns(  
    col.column("Expression column", new ExpressionColumn()))
  .setDataSource(...) 
private class ExpressionColumn extends AbstractSimpleExpression<String> {
  public String evaluate(ReportParameters reportParameters) {  
    return ...;
  }         
}
 
Another example: ExpressionColumnReport

Percentage column

It is represented by a PercentageColumnBuilder instance. It calculates percentage values from the field or column values.
Builders

methoddescription
col.percentageColumn(ValueColumnBuilder<?, ? extends Number> column),
col. percentageColumn(String title, ValueColumnBuilder<?, ? extends Number> column)
Creates a new percentage column from the column values
- title (optional) - the column title
- column - the column definition
col.percentageColumn(String fieldName, Class<? extends Number> valueClass),
col.percentageColumn(String title, String fieldName, Class<? extends Number> valueClass)
Creates a new percentage column from the field values
- title (optional) - the column title
- fieldName - the name of the field
- valueClass - the field value class
col.percentageColumn(FieldBuilder<? extends Number> field),
col.percentageColumn(String title, FieldBuilder<? extends Number> field)
Creates a new percentage column from the field values
- title (optional) - the column title
- field - the field definition

Configuration options

methoddescription
setTotalType(PercentageTotalType totalType) Sets the total type. Has effect only when the report contains at least one group
setTotalGroup(GroupBuilder<?> totalGroup) Sets the total group. Has effect only when the report contains at least one group

Examples
Quick usage:

TextColumnBuilder<Integer> quantityColumn = col.column("Quantity", "quantity", type.integerType());  
PercentageColumnBuilder quantityPercColumn = col.percentageColumn("Quantity [%]", quantityColumn); 
report()
  .columns(  
    quantityColumn, quantityPercColumn)
  .setDataSource(...) 
 
Another example: PercentageColumnsReport

Row number column

It is represented by a TextColumnBuilder instance and displays row numbers.
Builders

methoddescription
col.columnRowNumberColumn(),
col.columnRowNumberColumn(String title)
Creates a new row number column, the row number is reset on each new column
- title (optional) - the column title
col.pageRowNumberColumn(),
col.pageRowNumberColumn(String title)
Creates a new row number column, the row number is reset on each new page
- title (optional) - the column title
col.reportRowNumberColumn(),
col.reportRowNumberColumn(String title)
Creates a new row number column
- title (optional) - the column title

Examples
Quick usage:

report()
  .columns(  
    col.reportRowNumberColumn("Report row"))
  .setDataSource(...) 
 
Another example: RowNumberColumnsReport

Boolean column

It is represented by a BooleanColumnBuilder instance and shows a boolean value either as a text or as an image.
Builders

methoddescription
col.booleanColumn(String fieldName),
col.booleanColumn(String title, String fieldName)
Creates a new boolean column
- title (optional) - the column title
- fieldName - the name of the field
col.booleanColumn(FieldBuilder<Boolean> field),
col.booleanColumn(String title, FieldBuilder<Boolean> field)
Creates a new boolean column
- title (optional) - the column title
- field - the field definition
col.booleanColumn(DRIExpression<Boolean> expression),
col.booleanColumn(String title, DRIExpression<Boolean> expression)
Creates a new boolean column
- title (optional) - the column title
- expression - the boolean value expression

Configuration options

methoddescription
setComponentType(BooleanComponentType booleanComponentType) Sets the boolean presentation type.
BooleanComponentType.TEXT_* - shows a text value
BooleanComponentType.IMAGE_* - shows an image
setImageDimension(Integer width, Integer height),
setImageWidth(Integer width),
setImageHeight(Integer height)
Sets the boolean image dimension. Has effect only when the boolean value is presented as an image

Examples
Quick usage:

report()
  .columns(  
    col.booleanColumn("Boolean", "boolean"),  
col.booleanColumn("Boolean", "boolean").setComponentType(BooleanComponentType.IMAGE_STYLE_1))
  .setDataSource(...) 
 
Another example: BooleanColumnReport

Component column

It is represented by a ComponentColumnBuilder instance and is used to display custom components (e.g. images or complex content) in columns.
Builders

methoddescription
col.componentColumn(ComponentBuilder<?, ?> component),
col.componentColumn(String title, ComponentBuilder<?, ?> component)
Creates a new component column
- title (optional) - the column title
- component - the component definition

Examples
Quick usage:

ImageBuilder image = cmp.image(...);
ComponentBuilder<?, ?> component = ...;
report() 
  .columns(  
    col.componentColumn("Image", image), 
    col.componentColumn("Component", component))  
  .setDataSource(...) 
 
Another example: ComponentColumnReport

Tags: column

Latest News

  • Thu
    Jan
    25
    Changes in version 5.1.0 upgrade to JasperReports 6.5.1 removed xhtml and excelapi exporter removed thread safety...
  • Fri
    Jan
    27
    Changes in version 5.0.0 upgrade to JasperReports 6.4.0 upgrade to Java 1.7, DynamicReports is no longer compatibl...
  • Thu
    Jul
    28
    Changes in version 4.1.1 upgrade to JasperReports 6.2.2 added new types of component stretch type minor bug fixes...