Filters

Filters in a report define which filter fields will be displayed to the user and how these fields will be mapped to the SqlDef parameters defined in the where class at runtime.

Filters element takes an attribute: bindSqlNulls. The default value is true. This will allow any filter value which was not provided will be bound as a true SQL null. (The only exceptions to this are required Booleans, which are bound as 0 when a required check box filter is left unchecked.)

Filters can be defined in two ways:

  • FilterField. In the cases where filters are based on predefined field where the field name in the report matches the field name in the model, filter field is used.

    <FilterField levelType="ZBKS.Book" category="PDF" optional="false">
    <FieldName>Title</FieldName>
    </FilterField>
      

In this case, your filter parameter in the query should be in pure upper case (table column name can be in upper or lower case) like

${filterIfNotNull:TITLE, title = $TITLE$}
  • FilterField also supports the Optional element to specify if the filter is required to execute the report. By default, all filters are optional.

  • Custom Filter Field. When we want to define virtual filters where the field does not exactly map to the field in the model, then CustomFilterFields must be used instead of FilterFields.

    <CustomFilterField>
    <FieldRef category="PDF" levelType="ZBKS.Book">
    <FieldName>Title</FieldName>
    </FieldRef>
    <Type>STRING</Type>
    <Optional>true</Optional>
    <SimpleMapping sqlName="TITLE"/>
    </CustomFilterField>