Example
|
---|
array( "id" => "NAME", "name" => "Name" ) |
fetchSettingsFromQuery
array|null public static \Bitrix\Main\UI\Filter\Options::fetchSettingsFromQuery( array $fields = array(), \Bitrix\Main\HttpRequest $request );
Static method gets field values from query. Method returns array with values or null
on failure.
Parameters
Parameter | Description | Version |
---|---|---|
$fields | Array with fields.
Each fields must contain mandatory properties and can contain optional properties as well, specific to a field type (see. item Field properties below). | |
$request | Query - object of class HttpRequest |
Field properties
Properties for all field types:
Key | Type | Required | Default value | Description |
id | String | Yes | Field identifier. For example, NAME , USERNAME | |
name | String | Yes | Displayed field name. It will be shown to user. | |
default | Boolean | No | false | Defines, if field as shown by default. |
type | Boolean | No | "string" | Defines field type. |
Field properties depending on the type:
(by default, without specific type, fields are converted "string" type)- string (строка)
You may skip indicating string fields type as having a string type. Just as well, you can directly indicate field type as
"string"
. - list (list)
Lists can have singular or multiple selection. Uses singular single selection by default.
Additional properties Key Type Required Default value Description params Array No array("multiple" => "N")
Defines list parameters. Can contain property multiple
with the value"Y"|"N"
. Property determines, if list has multiple selection.items Array No array("Not specified")
Associative array, defining search items. Example- List with singular selection.
array( "id" => "MARK", "name" => "Rating", "type" => "list", "items" => array( "P" => "Positive", "N" => "Negative", ) )
- 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 without my participation", ) )
- List with singular selection.
- custom_date (arbitrary date)
Allows performing complex filtering by dates. This field allows select items, which, for example, were created on the 1st of April and December, in 2012 and 2014.
Examplearray( "id" => "DATE_CREATE", "name" => "Date created", "type" => "custom_date" )
- date (дата)
Date type fields can support several types of values, declared in
\Bitrix\Main\UI\Filter\DateType
. It is a "precise date", "range", "recent N days" and etc.Additional properties Key Type Required Default value Description time Boolean No false Enables time support. exclude Array No array() Defines, which value types to be excluded from current field. Value types are declared in \Bitrix\Main\UI\Filter\DateType
.Examples- Standard field.
array( "id" => "DATE_START", "name" => "Start date", "type" => "date" )
- Field with time support.
array( "id" => "DATE_START", "name" => "Start date", "type" => "date", "time" => true )
- Field with excluded value types.
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 ) )
- Standard field.
- number (numeric)
Numeric field type can support several value types, declared in
\Bitrix\Main\UI\Filter\NumberType
.Examplearray( "id" => "ID", "name" => "ID", "type" => "number" )
- checkbox (чекбокс)
Checkbox type field implements list type field with preset list items. Checkbox, in contrast to native control, has three values: "Yes", "No" and "Not selected".
Additional properties Key Type Required Default value Description valueType String No "" Defines type of returned value. Can accept "numeric"
value or an empty string. When"numeric"
is specified, returns1|0
as value. If not specified, or a specified value is different from"numeric"
, returnsY|N
.Examplearray( "id" => "IS_CHECKED", "name" => "Checkbox", "type" => "checkbox" )
- custom_entity (entity selection)
Implements user and software interface for interaction with data outside filter. For example, CRM entity selection, group, user selection and etc.
Additional properties Key Type Required Default value Description valueType String No "" Defines type of returned value. Can accept "numeric"
value or an empty string. When"numeric"
is specified, returns1|0
as value. If not specified, or a specified value is different from"numeric"
, returnsY|N
.params Array No array("multiple" => "N")
Defines field parameters. It can contain property multiple
with value"Y"/"N"
. The property defines, if multiple selection is supported.User interface is implemented as text field with inserted values.
Software interface implements set of Javascript events and field object with set of methods for interaction with it.
Events:
- customEntityFocus [Field:BX.Main.ui.CustomEntity] - triggered, when field is in focus. Usually, this a popup window with possible field value options is shown next to this field.
- customEntityBlur [Field:BX.Main.ui.CustomEntity] - triggered, when field has lost focus. Usually, this event closes previously displayed popup window. Event is not triggered, when focus shifts to the popup window.
- customEntityRemove [Field:BX.Main.ui.CustomEntity] - triggered, when user has deleted a field.
Methods:
- BX.Main.ui.CustomEntity.setData (label:string, value:string|items:object[]) : void - sets a field value.
Field parameters with single selection of value Parameter Type Required Description label String Yes Value, shown to user. value String Yes Value to be returned by filter. Field parameters with value multiple selection support Parameter Type Required Description item Object[] Yes Array with object with properties label
andvalue
.value String Yes Value to be returned by filter. - BX.Main.ui.CustomEntity.setPopupContainer (container:HTMLElement) : void - sets popup window container. It's required for correct event processing.
- BX.Main.ui.CustomEntity.getCurrentValues () : object - returns current field value. Returns object with properties
label
,value
. - BX.Main.ui.CustomEntity.getField () : ?HTMLElement - returns link to the root field item.
- BX.Main.ui.CustomEntity.getLabelNode () : ?HTMLInputElement - returns link to input field item.
- BX.Main.ui.CustomEntity.isMultiple () : Boolean - checks, if the field is multiple.
ExampleCreate a field, which when clicked, opens a popup with option to select a value.
Add field to a filterarray( "id" => "CREATED_BY", "name" => "Created by", "type" => "custom_entity" )
Create an event handlerBX.addCustomEvent('BX.Main.Filter:customEntityFocus', onFieldFocus); BX.addCustomEvent('BX.Main.Filter:customEntityBlur', onFieldBlur); function onFieldFocus(Field) { // Set link to a window container // BX.Main.ui.CustomEntity.setPopupContainer(container) // Show a popup window } function onFieldBlur() { // Hide the window }