Thursday, April 22, 2010

Multi-View Report Items

BIRT currently supports the concept of a multi-view report item. What this means is that two report items share the same data bindings and physical space, but only one is displayed. In the current version of BIRT only tables and crosstabs support this multi-view feature and the second view must be a chart. Generally the view that is displayed is chosen at design time, but this can be altered using some script and a report parameter.

To create a multi-view report item, first create a table or crosstab. Next right click on the report item and select Create Chart View.

This will launch t he Chart Builder. Construct the chart as usual. After creating the chart a second tab will appear at the bottom of the report item.

The tab selected currently determines which view will be displayed. The selected view can also be changed with script and a report parameter. First select the table tab and name the table.

In this case I have named the table “mytable”. Next add a report parameter to use in the script. The parameter should allow two choices, show as chart or show as table. In this example I have named the report parameter ShowAs and the parameter has chartview or tableview as possible values.

Finally enter the following script in the beforeFactory event.

var th = reportContext.getDesignHandle().findElement("mytable");
var mvh = th.getProperty("multiViews");

if( params["ShowAs"].value == "chartview" ){
mvh.setProperty("index", "0" );
mvh.setProperty("index", "-1" );

The first line retrieves a handle to the table and the second retrieves a handle to the multiviews property for the table. The parameter is then used to set the index for the multiview item.

The output will look similar to:


This example is available at Birt-Exchange.