Documentation

UiFilterPreset

Class for converting block filter into the format main.ui.filter. It's used in configurable filter for data retrieval.

Method Description Available from version
construct Constructor
addCheckboxValue Converts checkbox type value into the format bitrix:main.ui.filter.
addCustomDateValue Converts date range type value into the format bitrix:main.ui.filter.
addDateValue Converts date or date/time type value into the format bitrix:main.ui.filter.
addDestSelectorValue Converts entity binding type value into the format bitrix:main.ui.filter.
addListValue Converts list/multiple list type value into the format bitrix:main.ui.filter.
addNumberValue Converts integer type value into the format bitrix:main.ui.filter.
addStringValue Converts string type value into the format bitrix:main.ui.filter.
create Converts block filter into the format bitrix:main.ui.filter.
initFieldTypeHandlers Service method completes list of supported field types.

Example

Initializing component bitrix:main.ui.filter using values from block filter when opening a settings form (configurable filter for data retrieval). Please, be advised that the example below doesn't have the key operators for the fields, because it's not required (but its not prohibited).

$gridFilterConfig = new UI\Filter\Options('filter_ID');

      $preset = [];
      $request = \Bitrix\Main\Context::getCurrent()->getRequest();
      $data = $request->getPost('filter'); // this key passes the block filter to the form
      if (!empty($data) && is_array($data))
      {
         $fields = []; // filter fields - see the format
         $fields['NAME'] = [
            'id' => 'NAME',
            'type' => 'string',
         ];
         $fields['ID'] = [
            'id' => 'ID',
            'type' => 'number',
         ];
         $fields['ENTITY_LIST'] = [
            'id' => 'ENTITY_LIST',
            'type' => 'list',
            'params' => [
               'multiple' => 'Y'
            ]
         ];
         $fields['ACTIVE'] = [
            'id' => 'ACTIVE',
            'type' => 'checkbox',
            'operators' => [
               'default' => ''
            ]
         ];

         $sourceFilter = new \Bitrix\Landing\Source\UiFilterPreset();
         $sourceFilter->setFields($fields);
         $preset = $sourceFilter->create($data);
      }

      $gridFilterConfig->setFilterSettings(
           \Bitrix\Main\UI\Filter\Options::TMP_FILTER,
           [
              'name' => '',
              'fields' => $preset
           ],
           true,
           false
        );
        $gridFilterConfig->save();


© «Bitrix24», 2001-2024
Up