Enabling dynamic filter conditions
The previous section described how to create a filter that uses a report parameter to obtain the filter condition value at run time. The following expression is an example of such a filter:
row["Total"] Greater than or Equal params[Sales Total].value
The field to evaluate (row["Total"]) and the operator that determines the type of filter test (Greater than or Equal) are specified at design time. At run time, the report user supplies the parameter value, which, in this example, is a sales total, such as 10000.
In BIRT Report Designer Professional, report parameters and filters are enhanced to support dynamic filter conditions, which provide users more control over what data they see in the report. Instead of specifying only the value on which to filter, the report user can specify conditions, such as Total Less than 10000, or Total Between 10000 and 20000, or Total Greater than 20000. The user can also choose to view all totals; in other words, the user can choose to omit the filter condition.
Another enhancement is that these filters can modify the underlying query so that filtering occurs in the database. This functionality applies when accessing a database through an information object or a JDBC connection for query builder data source. When using these data source types, only data rows that meet the filter criteria are retrieved from the database. By retrieving a limited number of rows, BIRT Report Designer Professional’s performance improves.
To enable users to specify a dynamic filter condition, complete the following tasks in the recommended order:
*Create a dynamic filter report parameter.
*Create a dynamic filter and bind it to the report parameter.
Creating a dynamic filter report parameter
A dynamic filter report parameter differs from a regular report parameter in one important aspect. Using a dynamic filter parameter, you can provide report users with a list of operators, which they can use to construct their own filter condition.
Figure 13‑12 shows an example definition of a dynamic filter parameter where the display type is a text box. Aside from the Dynamic Filter Condition section, where you specify the column on which to filter and the operators to provide to users, the properties are similar to the properties for a regular report parameter.
Figure 13‑12 Properties of a dynamic filter parameter whose display type is a text box
Like the regular report parameter, a dynamic filter parameter can also provide the user with a list of values. However, values can be presented in a combo box or list box only. Figure 13‑13 shows an example definition of a dynamic filter parameter that includes a list of values. The display type is set to Combo/List Box.
Figure 13‑13 Properties of a dynamic filter parameter whose display type is a combo box or list box
How to create a dynamic filter report parameter
1 In Data Explorer, right-click Report Parameters, and choose New Dynamic Filter Parameter.
2 Specify the properties of the dynamic filter parameter. Most are the same as the properties for a regular report parameter. The following Dynamic Filter Condition properties are specific to a dynamic filter parameter:
*In Column, type the name of the field on which to filter.
*In Operator, select the operators to provide to the user. By default, all the operators are selected. To remove an operator, select it and click <.
*Optionally, set one of the operators as the default. Select the operator, then choose Set as Default. A check mark appears next to the operator. If you specify a default operator, you must also specify a value in Default Value.
3 Choose OK.
Making a dynamic filter parameter optional
When you create a dynamic filter parameter, you can require the user to specify a value or you can make the filter optional. It is usually good practice to make the filter optional, so that the user can view a report with all the data. For example, if a report displays inventory data by vendor and you create an optional parameter to filter on vendors, the user can select No Condition to view inventory data for all vendors.
On the other hand, you can require that the user specify a value if displaying all the data results in a very long report. A report that runs into hundreds of pages is not only difficult to read, but the report takes longer to generate.
To make a filter parameter optional, deselect the Is Required property.
Accepting multiple values
Users often want to select any number of values for a filter condition. In an inventory report, for example, the user might need to view data for several vendors. To support the selection of multiple values, create a dynamic filter parameter as follows:
*Select Combo/List Box as the display type.
*Select the In operator as one of the operators to provide to the user.
*Create a list of values.
Creating a dynamic filter
BIRT Report Designer Professional supports two types of filters: static and dynamic. Use a static filter to define a specific filter condition at design time. Use a dynamic filter to enable users to define a filter condition at report run time.
How to create a dynamic filter
This procedure assumes you have already created the dynamic filter report parameter to bind to the filter you are creating.
1 Select the element to which to apply a dynamic filter condition. For example, select a data set, a table, or a chart whose data you want to filter.
2 Choose Filters, then choose New or Add to define a filter.
3 In New Filter Condition, specify the following values:
1 Choose Dynamic.
2 In Column, select the field on which to filter.
3 In Filter Parameter, select the dynamic filter parameter to update this filter with user-specified values at run time.
Figure 13‑14 shows an example in which a QUANTITYINSTOCK field is bound to a dynamic filter parameter named Quantity.
Figure 13‑14 Definition of a dynamic filter condition
4 Choose OK.
The filter appears on the Filters page. Figure 13‑15 shows the Quantity dynamic filter on the Filter page of the data set editor. Unlike a static filter, no values appear under Operator, Value 1, or Value 2, indicating that these values are specified at run time.
Figure 13‑15 Dynamic filter in a data set