Filter (main.ui.filter)
Description
Component main.ui.filter(Bitrix\Main\UI\Filter classes) displays filter + search. It is a system component.
It can be found in the folder /bitrix/components/bitrix/main.ui.filter
.
Parameters
Parameter | Type | Description |
---|---|---|
FILTER_ID | string | Filter ID (must be unique). |
GRID_ID | string | Grid ID. Specify it when planning to use filter jointly with grid. When specified, filter will be independently update grid when filtering. |
FILTER | array | Array with fields. The following field types are available for filtering:
|
ENABLE_LABEL | bool | Enables showing filter fields headers. |
ENABLE_LIVE_SEARCH | bool | Enables “live filtration” during search bar input. |
FILTER_PRESETS | array | Filter presets. |
ENABLE_FIELDS_SEARCH | bool | Enables filtering by field name. |
HEADERS_SECTIONS | array | Array for field grouping in main.ui.filter as follows:
array ( 0 => array ( 'id' => 'DEAL', 'name' => 'My name', 'default' => true, - include all fields in this section without direct section binding 'selected' => true, - section is shown by default ), 1 => array ( 'id' => 'CONTACT', 'name' => 'This the first contact‚', 'selected' => true, ), 2 => array ( 'id' => 'COMPANY', 'name' => 'This the second contact', 'selected' => true, ), ) |
DISABLE_SEARCH | bool | Disabling full-text search. |
Call example
<?$APPLICATION->IncludeComponent( 'bitrix:main.ui.filter', '', [ 'FILTER_ID' => 'report_list', 'GRID_ID' => 'report_list', 'FILTER' => [ ['id' => 'DATE', 'name' => 'Date', 'type' => 'date'], ['id' => 'IS_SPEND', 'name' => 'Operation type', 'type' => 'list', 'items' => ['' => 'Any', 'P' => 'Credit', 'M' => 'Debit'], 'params' => ['multiple' => 'Y'] ], ['id' => 'AMOUNT', 'name' => 'Sum', 'type' => 'number'], ['id' => 'PAYER_INN', 'name' => 'Payer INN', 'type' => 'number'], ['id' => 'PAYER_NAME', 'name' => 'Payer'], ], 'ENABLE_LIVE_SEARCH' => true, 'ENABLE_LABEL' => true ] );?>
Presets
Use parameter FILTER_PRESETS
to create presets. Pass an associative array to this parameter, where preset ID is indicated as key, and preset parameters as filter parameters. The filter is located in the table b_user_option. Category main.interface.grid
"FILTER_PRESETS" => [ "myPresetId" => [ "name" => 'Preset name', "default" => 'true', // if true - preset by default "fields" => [ "FIELD_1_ID" => "field_1_value", "FIELD_2_ID" => "field_2_value", ] ] ]
Specifics of handling some field types
Type list - list.
Lists can have a single or multiple selection; a single selection is used by default. It has the following additional features:
Key | Type | Default value | Description |
---|---|---|---|
params | array | array("multiple" => "N") | Defines list parameters. Can contain a 'multiple' property with value "Y"|"N". This property determines if a list has a multiple selection feature. |
items | array | array("Not selected") | Associative array that defines list elements. |
// Example 1. List with single election array( "id" => "MARK", "name" => "Rating", "type" => "list", "items" => array( "P" => "Positive", "N" => "Negative", ) ) // Example 2. List with multiple selection. array( "id" => "PARAMS", "name" => "Task parameters", "type" => "list", "params" => array( "multiple" => "Y", ), "items" => array( "MARKED" => "Rated", "IN_REPORT" => "In report", "OVERDUED" => "Overdue", "ANY_TASK" => "Show tasks where I do not participate", ) )
Field type date
Date type fields can support several types of values in \Bitrix\Main\UI\Filter\DateType. For example, “exact date”, “range”, “last N days” and etc. To exclude values:array( "id" => "DATE_START", "name" => "Start date", "type" => "date", "exclude" => array( \Bitrix\Main\UI\Filter\DateType::LAST_7_DAYS, \Bitrix\Main\UI\Filter\DateType::LAST_30_DAYS, \Bitrix\Main\UI\Filter\DateType::LAST_60_DAYS, \Bitrix\Main\UI\Filter\DateType::LAST_90_DAYS ) )To enable support of time, use the time property:
array( "id" => "DATE_START", "name" => "Start date", "type" => "date", "time" => true )
Type: custom_entity
Implements user and program interface to interact with data outside the filter. For example, CRM entity selection, workgroup, user selection and etc.Key | Type | Default value | Description |
---|---|---|---|
valueType | string | " " | Defines type of returned value. Can have a "numeric" value or an empty string. When specifies "numeric", then value will be returned as 1/0, when not specified, or value specified is different from "numeric", returns Y/N |
params | array | array("multiple" => "N") | Determines field parameters. Can contain a "multiple" property with value "Y"/"N". This property determines if multiple selection is supported. |
Example:
// Add field to filter array( "id" => "CREATED_BY", "name" => "Created by", "type" => "custom_entity" ) // Create event handler BX.addCustomEvent('BX.Main.Filter:customEntityFocus', onFieldFocus); BX.addCustomEvent('BX.Main.Filter:customEntityBlur', onFieldBlur); function onFieldFocus(Field) { // Set link to a popup window container // BX.Main.ui.CustomEntity.setPopupContainer(container) // Show a popup window } function onFieldBlur() { // Hide window }
Entity selection dialog. Type: entity_selector
Note: starting from Main module version 21.200.0 (main) the component main.ui.filter now has support of entity selection dialog.
Implements interface for selecting elements via EntitySelector: entity selection dialog.
Uses the type custom_entity described above as the basic field. User interface is implemented as text field with inserted values.
Upon focusing on the enter field, shows entity selection dialog with option to search by entered text.
Key | Type | Required | Default value | Description |
---|---|---|---|---|
multiple | Bool | No | array('multiple' => 'N') | Receives values 'Y'|'N'. Defines if entity selection is multiple. |
addEntityIdToResult | Bool | No | array('addEntityIdToResult' => 'N') | Receives values 'Y'|'N'. Defines, necessary to add entity type ID to generated value. |
dialogOptions | Array | No | - | Associative array that defines settings for entity selection dialog. |
With addEntityIdToResult=Y
, the selected value will be generated as an array in JSON format. Array contains two elements:
- entity type ID;
- entity ID (similar с ItemId у EntitySelector).
This flag can be used when several types of entities are available for selection.
dialogOptions array structure matches to [link=13503304]DialogOptions[/link] object fields for entity selection dialog. Correspondingly, dynamic and static lists of elements are supported.
Examples
Example 1. User selection
$field = [ 'id' => 'USER_ID', 'name' => 'User', 'type' => 'entity_selector', 'params' => [ 'multiple' => 'Y', 'dialogOptions' => [ 'height' => 240, 'context' => 'filter', 'entities' => [ [ 'id' => 'user', 'options' => [ 'inviteEmployeeLink' => false ], ], [ 'id' => 'department', ] ] ], ], ];
Example 2. Selection from static list
This example uses entities of various types. That's why this addEntityIdToResult flag is set for resulting filter to get full information about selected element.
$field = [ 'id' => 'STUFF', 'name' => 'Miscellaneous', 'type' => 'entity_selector', 'params' => [ 'multiple' => 'N', 'addEntityIdToResult' => 'Y', 'dialogOptions' => [ 'items' => [ [ 'id' => 1, 'entityId' => 'my-entity', 'title' => 'Пункт A', 'tabs' => 'my-tab' ], [ 'id' => 2, 'entityId' => 'my-entity', 'title' => 'Пункт B', 'tabs' => 'my-tab' ], [ 'id' => 3, 'entityId' => 'my-entity', 'title' => 'Пункт C', 'tabs' => 'my-tab' ], [ 'id' => 1, 'entityId' => 'my-user', 'title' => 'John Smith', 'tabs' => 'my-tab' ], [ 'id' => 2, 'entityId' => 'my-user', 'title' => 'Jeremy Smith', 'tabs' => 'my-tab' ], [ 'id' => 'USD', 'entityId' => 'my-currency', 'title' => 'USD', 'tabs' => 'my-tab' ], ], 'tabs' => [ [ 'id' => 'my-tab', 'title' => 'My tab' ] ], 'showAvatars' => false, ] ], ];