### Applying filters

You can apply filters to business views and data components such as tables, crosstabs and charts of a web report so as to narrow down the data displayed in the web report.

#### Applying filters to business views

When creating web reports, you can choose to apply some filter to the specified business view to narrow down the data scope of the data component using the business view.

In Web Report Studio, filters for business views are defined into two categories: predefined filters and user defined filters. As the name suggests, predefined filters are defined in advance when creating or editing the business views in JReport Designer, and user defined filters are created on business views while they are used.

Filters can be applied to a business view in the report wizard.

1. In the report wizard, select the business view that you are going to add filters to from the Data Source drop-down list, and then click the Filter button on the right. The Query Filter dialog appears.
2. The dialog has the basic and advanced modes for you to define a filter using either simple expressions or complex expressions.

   When it is in the advanced mode, you can also choose to apply a predefined filter of the specified business view from the Query Filter drop-down list. If you prefer to define a filter on your own, select User Defined from the drop-down list, and then define the filter according to your requirements. You can also edit a predefined filter if required and save it as a user defined filter to the business view.

   - To define a filter using simple expressions:
     1. Make sure the dialog is in the basic mode. See the dialog.

     2. Select the field on which the filter will be based from the field drop-down list.
     3. From the operator drop-down list, set the operator with which to compose the filter expression.
     4. Type the values of how to filter the field in the value text box, or select one or more values from the drop-down list. You can also click the button and then select a parameter from the drop-down list to specify the value dynamically and when the available parameters cannot meet your requirement, you can create a local parameter to use in the filter.
     5. If you want to add another condition line, from the logic operator drop-down list,
        - To add a condition line of the AND relationship with the current line, select AND, then define the expression as required.
        - To add a condition line of the OR relationship with the current line, select OR, then define the expression as required.

        Repeat this to add more filter expressions if required. To delete a condition line, click on its left.

   - To define a filter using complex expressions:
     1. Switch the dialog to the advanced mode. See the dialog.

     2. Click the Add Condition button to add a condition line.
     3. From the field drop-down list, select the field on which the filter will be based.
     4. From the operator drop-down list, set the operator with which to compose the filter expression.
     5. Type the values of how to filter the field in the value text box, or select one or more values from the drop-down list. You can also click the button and then select a parameter from the drop-down list to specify the value dynamically and when the available parameters cannot meet your requirement, you can create a local parameter to use in the filter.
     6. To add another condition line, click the Add Condition button and define the expression as required. Then click the logic button until you get the required logic to specify the relationship between the two filter expressions. The logic can be AND, OR, AND NOT, or OR NOT.
     7. Repeat the above steps to add more filter expressions if necessary.

        To group some conditions, select them and click the Group button, then the selected conditions will be added in one group and work as one line of filter expression. Conditions and groups together can be further grouped. To take any condition or group in a group out, select it and click Ungroup. It is the equivalent of adding parenthesis in a logic expression.

        To adjust the priority of a condition line or a group, select it and click the Up or Down button.

        To delete a condition line or a group, select it and click the Delete button.

3. After you finish the report wizard, the specified filter is applied to the business view. If parameters are used in the filter conditions, they are listed in the Parameters panel and you can specify the parameter values in the panel to dynamically define the filter conditions.

Note: Query filters take effect on the component level, which means each time you create a component, you can apply a filter to the business view the component uses and it will not affect other components based on the same business view.

#### Filtering the data components in a report

There are the following ways you can take in order to filter the data components in a web report.

##### Using the Filter dialog

When using the Filter dialog to filter report data, you can only make the filter applied to a specific data component in the current web report.

To filter report data using the Filter dialog:

1. Click Menu > Edit > Filter, or the Filter button on the Standard toolbar. The Filter dialog appears. See the dialog.

2. From the Apply to drop-down list, select the component in the web report to which you want to apply the filter.

   Tip: For web reports created in JReport Designer, the default selected component and available components in the Apply to drop-down list are determined by the Default for Filter and Invisible for Filter Dialogs properties of the components in the web reports.

3. Define the filter using either simple expressions or complex expressions.
4. When done, click OK to apply the filter. If parameters are used in the filter conditions, they are listed in the Parameters panel and you can specify the parameter values in the panel to dynamically define the filter conditions.

The Filter dialog provides an entry to all the filters used in the current web report. You can click the Inspector button to view the detailed filter information in the Filter Inspector dialog.

##### Using filter controls

You can also use the Filter web control to filter one or more data components that use the same data source in a web report. A filter control can do filtering based on one field. For details, see Using filter control to filter report data.

##### Using the Filter panel

The Filter panel on the left of Web Report Studio is used to filter data components in the current report that are using the same business view. To do this:

1. Add group and detail resources into the Filter panel by clicking + on the panel title bar. Each added group/detail and its values are housed in a separate box. Group and detail objects can be selected from the business views used by current report.
2. Select the values you would like to filter the report data. The selected values applies a filter condition to all the data components in the current report that are using the same business view, regardless whether the data components contain the fields holding those values.

   You can make use of the Ctrl or Shift key to do multiple selection.

The value selection applies a filter condition and the logic is as follows:

- For one value selection:

  Selected_Field=Selected_Value

  For example, Country=USA

- For multiple selection:

  (Selected_Field1=Selected_Value1 or Selected_Field1=Selected_Value2) and (Selected_Field2=Selected_Value3 or Selected_Field2=Selected_Value4)...

  For example, (Country=USA or Country=China) and (Year=2008 or Year=2009)

The following shows more about working with the Filter panel:

You can use the buttons on the bottom of the Filter panel to deal with the value selection in the panel.

- Back
  Goes back to the previous value selection status and refreshes the report data accordingly.
- Clear
  Removes all the value selection histories and all the filter conditions based on the selections, and refreshes the report data accordingly.
- Forward
  Goes forward to the next value selection status and refreshes the report data accordingly.

After right-clicking on a group/detail name title bar, these options are available for managing the group/detail object.

- Search
  Displays the quick search toolbar right above the value list which enables you to search values in the group/detail object. You can also use the button on the group/detail name title bar to launch the quick search toolbar. For detailed usage about the quick search toolbar, refer to Select Values dialog.
- Clear
  Cancels the selection of values in the group/detail object. You can also use the button on the group/detail name title bar to achieve this.
- Clear All
  Cancels the selection of all values in all the group and detail objects.
- Sort
  Sorts the values in the group/detail object in the ascending or descending order.
- Delete
  Removes the group/detail object from the Filter panel and the filter you created with the object will be removed from the report too. You can also click X on the group/detail name title bar to remove it.

Notes:

- When there are more than 300 values for an object, JReport will use Big Data Loading logic. In this case, the Shift Key for multiple selection will not work.
- The filters created via the Filter panel cannot be seen when web reports are opened in JReport Designer.

Cascading relationship between filters

The Filter panel can be regarded as a collection of special filter controls which apply to all data components using the same data source. While common filter controls can choose the data components they apply, still under the circumstance of using the same data source.

When there are filter controls, including the special ones in the Filter panel, that apply to the same data components, and when these controls' fields have cascading relationship, the cascading relationship will be revealed when you select values in the controls.

For example, there is a filter control based on the field Country, a filter control on City, and another on State. The first two share one table while the third shares nothing with the other two. In this case, Country and City values will show cascading relationship, but State values will not participate. You select USA in the Country filter control, the values in the City filter control will change as follows if the control has scrollbar: the cities belong to USA are displayed in the upper area of the filter control, and the other cities are put in the lower area and grayed out. For the case that the City filter control has no scrollbar: all the values remain their positions and the values not belonging to USA are grayed out. In both cases all the values are selectable. But the State values remain as before, since the selection of them will not affect the data components that the Country and City filter controls control.

##### Using the shortcut menu

You can use filter-related commands on the shortcut menu to filter the data in a table. To do this, point to any value of the field other than the group by field, by which you want to filter data, then right-click to show the shortcut menu. You will see the Filter item which provides a submenu containing the following commands:

- Remove Filter
  This command is enabled after you have applied filtering on the field. Clicking this item will remove all filters on this field.
- First N
  Shows the First N item with which you can filter data to display records that meet the First N condition. You can select a number from the submenu or enter a positive integer into the text box on the submenu to specify the First N condition.

  For example, if you select 5 from the First N submenu for a certain field, then only the records with the field value equal to one of the first five field values will be displayed.

- Last N
  Shows the Last N item with which you can filter data to display records that meet the Last N condition. You can select a number from the submenu or enter a positive integer into the text box on the submenu to specify the Last N condition.

  For example, if you select 5 from the Last N submenu for a certain field, then only the records with the field value equal to one of the last five field values will be displayed.

- Field values
  "Field values" is not the name for a command on the Filter submenu, but represents some items which are the values of the field you right-click on. Selecting any field value listed here will make the table only display records with the field value equal to the selected one.
- More
  This command is enabled if the Filter submenu cannot list all field values. When it is enabled, clicking it will show the Select Values dialog, with which you can search for and select values conveniently with the help of the quick search toolbar.

##### Using labels

For tables in web reports, you can use a label to control the filter conditions. This feature needs to be enabled at report design time.

1. In JReport Designer, select a label in a table in a web report, and then set its Filterable property to true.
2. Set the field by which you want to filter records as the value of the label's Bind Column property.
3. Save the report and publish it to JReport Server.
4. Run the report in Web Report Studio, and you can find that a filter button displayed beside the label. Click it to show the Filter list, which contains the same items as the Filter submenu. Click the corresponding item to filter the records.

   After a filter is applied on the field specified by the Bind Column property, the button will be highlighted. You can still click it to show the Filter list to change the filter condition or select the All item to remove the filter on the field.

##### Using server profile setting

You can also configure the server profile to enable filter records in tables by clicking the filter button on table column headers.

1. Open the Profile > Customize Profile > Common tab.
2. Check the option Filter on Column Headers to enable clicking the filter button on column headers to filter table records.
3. Check Show Sort/Filter Status on Column Headers if you want the the filter button to be always displayed on the table column headers with the current filter status. If this option is unchecked, each time you want to get the filter button for a column, you need to put the mouse pointer on its header to make the button shown.
4. Run a web report containing a table in Web Report Studio and you can click on the table column headers to filter data.

   To filter the table based on any column field, click on its column header to show the Filter list, which contains the same items as the Filter submenu. Click the corresponding item to filter the records.

   After a filter is applied on a field, the button on its column header will be highlighted. You can still click it to show the Filter list to change the filter condition or select the All item to remove the filter on the field.

Notes:

- When filtering the data in a table by either shortcut menu, label or column header, you may notice that the corresponding filter expression displays in the Filter dialog if you open this dialog.
- The Filter on Column Headers feature does not work on summary columns that contain multiple summary fields.
- When a table is designed with the Filter by Label feature in JReport Designer, if the Filter on Column Headers option is also enabled on the server profile, the settings defined in JReport Designer have the higher priority for the specified columns.
- For web reports created in JReport Designer, the default selected component and available components in the Apply to drop-down list of the Filter dialog are determined by the Default for Filter and Invisible for Filter Dialogs properties of the components in the web report.