user8612546
user8612546

Reputation: 11

How to remove null/empty column from crosstab?

I have a cross tab element in my layout. One of the values in the column group is null and I don't want to display that column with null value in the output.

I have tried the checking the blank when null value and modifying print when expression property. But all it does is replacing the null value with blank but the column still comes in the output.

Current output

enter image description here

Expected output

enter image description here

Upvotes: 0

Views: 2439

Answers (1)

Petter Friberg
Petter Friberg

Reputation: 21710

To change the name in column header from null to something else you can modify the bucketExpression

<bucketExpression><![CDATA[($F{myField==null}?"New name":$F{myField})]]></bucketExpression>

Using this you can also move the values into a new bucket (column).

If you like to remove the whole column, AFIK there is no other method then to filter away the null values in your datasource before you pass it to the crosstab.

The options are:

  • If you are using an sql datasource just add the field in the where clause, for mysql that would be something like WHERE myField is not null

  • Use a filterExpression on your datasource eg.

    <filterExpression><![CDATA[($F{myField}!=null)]]></filterExpression> 
    
  • Develop a custom JRDatasource wrapping the datasource that ignores and jump if record has null value.

Conclusion: To remove the column, you need to remove the records from datasource before you pass it to crosstab.

Upvotes: 1

Related Questions