Grid Extension

The FilterBundle provides an extension for datagrid with ORM and Search datasources. Filters could be added to the datagrid in the datagrids.yml file for a specified datagrid under the filters node. Definition of any filter requires option data_name that should be referenced to column in the query and type (filter type).

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 SOME_DATAGRID:
     source:
         type: orm
         query:
             select:
                 - g.id
                 - g.label
             from:
                 - { table: OroContactBundle:Group, alias: g }

     filters:
         columns:
             SOME_FITLER_NAME: # uses for query param, and for setting default filters
                 type: string  # Filter type, list of available types described below
                 data_name: g.id
                 enabled: true|false #whether filter enabled or not. If filter is not enabled it will not be displayed in filter list but will be accessible in filter management.
                 disabled: true|false #If filter is disabled it will not be displayed in filter list and will not be available in filter management.
                 visible: true|false #If set to "false" - filter will not be displayed anywhere in UI. However, one can still set filter's value in backend or via url in frontend
                 force_like: true|false #Different search engines uses different methods for text search. When `force_like` is set to true, text-based filters will use simple `LIKE %%` OR `NOT LIKE %%`statement which depends on a chosen operator
                 min_length: integer #In case of text-based filters this option introduce possibility to ignore filters with less characters then specified. Validation message will also appear
                 divisor: number #In case of number-based filters this option will filter values rendered with datagrid divisor option.
                 case_insensitive: true|false #When set to 'true' text search filter will be case insensitive [Postgres only].
                 value_conversion: string #Callback for text search filter used for converting value passed to a query.

Default Values

String Filter

1
2
3
4
5
6
7
8
     filters:
         columns:
             fieldName:
                 type:      string
                 data_name: priorityLabel
                 case_insensitive: true
         default:
             fieldName: { value: 'someText', type: 'Oro\Bundle\FilterBundle\Form\Type\Filter\TextFilterType::TYPE_CONTAINS' }

Choice Filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
     filters:
         columns:
             period:
                 type: orocrm_period_filter
                 data_name: period
                 options:
                     populate_default: false
                     field_options:
                         choices:
                             monthPeriod:    Monthly
                             quarterPeriod:  Quarterly
                             yearPeriod:     Yearly
         default:
             period: { value: monthPeriod }

Additional Params

  • filter_condition - use OR or AND operator in expression
  • filter_by_having - filter expression should be added to HAVING clause
  • options - pass form options directly to filter form type (for additional info, see Filter Form Types).

Filters

String Filter

Provides filtering using string comparison.

type: string - Validated by TextFilterType in backend and rendered by Oro.Filter.ChoiceFilter. When case_insensitive is set to false, it is possible to convert value by using callback defined in ‘value_conversion’.

Select Row Filter

Provides filtering by selected/not selected records

type: string - Validated by SelectRowFilterType in backend.

Number and Percent Filter

Provides filtering by numbers comparison.

Note

Value from frontend will automatically transform to percentage for “percent” filter.

type: number - integer/decimal filter

Validated by NumberFilterType in backend and rendered by Oro.Filter.NumberFilter.

type: number-range - integer/decimal filter

type: percent - percent filter

type: currency - currency filter

Validated by NumberRangeFilterType in backend and rendered by Oro.Filter.NumberRangeFilter.

Boolean Filter

Provides filtering for boolean values.

type: boolean - Validated by BooleanFilterType in backend and rendered by Oro.Filter.ChoiceFilter with a predefined set of options (yes/no)

Choice Filter

Provides filtering data using a list of predefined choices

type: choice - Validated by ChoiceFilterType in backend and rendered by Oro.Filter.ChoiceFilter.

Entity Filter

Provides filtering data using list of choices that extracted from database.

type: entity - Validated by EntityFilterType in backend and rendered by Oro.Filter.ChoiceFilter.

Date Filter

Provides filtering data by date values

type: date - Validated by DateRangeFilterType. Rendered by Oro.Filter.DateFilter.

DateTime Filter

Provides filtering data by datetime values

type: datetime - Validated by DateTimeRangeFilterType. Rendered by Oro.Filter.DateTimeFilter.

DateGrouping Filter

Provides grouping dates using list of predefined choices: Day, Month, Quarter, Year

type: datetime - Validated by DateGroupingFilterType in backend and rendered by Oro.Filter.ChoiceFilter.

SkipEmptyPeriods Filter

Provides skipping empty data using list of predefined choices: Yes, No

type: choice - Validated by SkipEmptyPeriodsFilterType in backend and rendered by Oro.Filter.ChoiceFilter.

Customization

To implement your filter you have to do following:

  • Develop class that implements Oro\Bundle\FilterBundle\Filter\FilterInterface (also there is basic implementation in AbstractFilter class)
  • Register your filter as service with tag { name: oro_filter.extension.orm_filter.filter, type: YOUR_FILTER_TYPE }