A filter on one or more columns reduces unwanted data in reports. For example, financial reports for the current fiscal year may need data from the previous fiscal year for comparison, but nothing earlier. It's good practice to filter out irrelevant data to reduce the size of query results and processing time.
Also, reports based directly on the Domain can define their own filters. Putting often-used filters in the Domain design avoids the need for each user to define filters independently and also reduces the chance for errors.
You can define a filter on a column you don't plan to expose in the Domain. The filter remains active and only data that satisfies all defined filters appears to report users. For example, you can filter data to select a single country, in which case it doesn’t make sense for the column to appear in a report. However, you should clearly document such data restrictions in the description of the Domain, so users understand what data is accessible through the Domain.
You have two options for defining the parameters of the filter:
• | Define the parameters statically, so they are the same for every user. |
• | Have the server derive the parameter of the filter at run time based on attributes you provide. |
For example, you can create a filter to show data for a single country. You could create a static filter that filters out data for every country except the USA. If you want to create a filter that only shows data for the logged in user's country, you can create a Country attribute for your users in their profiles and enter the name of their country, which must match one of the country names used in the Domain's data source. When creating the filter, you can use the parameter attribute('Country') to filter out data for all countries except the user's country.
The data type for the attribute is automatically based on the filtered column's field type. For example, if you are creating a filter based on a Date column, the attribute parameter will return a Date value.
When referring to an attribute, you can specify the attribute categorically or hierarchically:
• | Categorical reference – If you specify a category for the attribute value, the server attempts to find that particular value of the attribute. You can specify these attribute categories: |
• | User – In the attributes defined on the logged-in user. |
• | Tenant – In the attributes defined on the organization of the logged-in user. |
• | Server – In the attributes defined at the server-level. |
• | Hierarchical reference - If you don't specify a category for the attribute, the filter searches attributes hierarchically and uses the value for the first attribute it finds with the given name. This search starts with the logged in user, then proceeds to the user's organization and parent organization, and finally to the server level. |
A categorical reference would use attribute('Country', 'User') to specify itself as a user attribute while a hierarchical one would use attribute('Country'). Use 'Tenant' or 'Server' in the attribute instead of 'User' to search at those levels.
If the specified attribute is not found, the filter will fail.
For more information on attributes, see the section "Managing Attributes" in the JasperReports Server Administrator Guide.
To define a filter:
1. | Double-click a column in Fields. |
Alternatively, you can drag a column to the Filters panel. The column appears in the Filters panel with a list of conditional operators you can apply to that column.
2. | Choose the comparison operator and filter value from the drop-down. |
In the Filters panel, the choice of comparison operators depends on the column's datatype. For example, strings offer a choice of search operators and dates offer time comparison operators. The filter value depends on the datatype and comparison operator. For example, if you select a date column with the is between operator, the Filters panel displays two calendar widgets for specifying a date range:
Filters Panel of the Domain Designer |
Text columns have both substring comparison operators such as starts with or contains and whole string matching such as equals or is one of. When you select a whole string matching operator, the panel displays a list of all existing values for the chosen column, retrieved in real-time from the database. If more than 50 values are available, use search to narrow the list. For multiple value matching, double-click the available values to select them. You may perform multiple searches and select values from each list of results.
To define a filter that compares two columns of the same datatype, Select both columns, and drag them to the Filters panel. |
If you want to use an attribute for a parameter, enter the attribute in the field using the syntax attribute('<attrName>'). For example, if you want to use an attribute called Cities in the filter, enter attribute('Cities') into the field. If you want to specify that this is a user attribute, and not an organizational or server one, enter attribute('Cities', 'User').
3. | Click OK to define the filter. |
Filters shows all the filters you have defined. The overall filter applied to the data is the logical AND of all conditions you defined.
In Filters, click Change to modify a filter you defined. Click OK to save the changes. To remove a row from the list, select it and click Remove.
Recommended Comments
There are no comments to display.