K
K
Katsuro2021-03-27 20:15:08
PHP
Katsuro, 2021-03-27 20:15:08

How to link a filter and a table in Bitrix 24?

This is the code for linking a table with a filter, everything is displayed, pagination works, but the filter does not work (I write a name, but it does not search, it's just that the table is empty), although it takes a value on request, who has come across and done something similar, please help

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Список заданий бизнес процессов");

use \Bitrix\Iblock\PropertyEnumerationTable;
use Bitrix\Main\Grid\Options as GridOptions;
use Bitrix\Main\UI\PageNavigation;
CModule::IncludeModule("bizproc");

$list_id = 'report_list';

$grid_options = new GridOptions($list_id);
$sort = $grid_options->GetSorting(['sort' => ['NAME' => 'DESC'], 'vars' => ['by' => 'by', 'order' => 'order']]);
$nav_params = $grid_options->GetNavParams();

$nav = new PageNavigation('report_list');
$nav->allowAllRecords(true)
  ->setPageSize($nav_params['nPageSize'])
  ->initFromUri();

if ($nav->allRecordsShown()) {
  $nav_params = false;
} else {
  $nav_params['iNumPage'] = $nav->getCurrentPage();
}

$ui_filter = [
  ['id' => 'NAME', 'name' => 'Название', 'type'=>'text', 'default' => true],
];

$filterOption = new Bitrix\Main\UI\Filter\Options($list_id);
$filterData = $filterOption->getFilter([]);

foreach ($filterData as $k => $v) {
 $filterData['NAME'] = "%".$filterData['FIND']."%";
}

$APPLICATION->IncludeComponent('bitrix:main.ui.filter', '', [
  'FILTER_ID' => 'report_list',
  'GRID_ID' => 'report_list',
  'FILTER' => $ui_filter,
  'ENABLE_LIVE_SEARCH' => true,
  'ENABLE_LABEL' => true
]);

$filterData['ACTIVE'] = "Y";

$columns = [];
$columns[] = ['id' => 'ID', 'name' => 'ID', 'sort' => 'ID', 'default' => true];
$columns[] = ['id' => 'NAME', 'name' => 'Название', 'sort' => 'NAME', 'default' => true];

$res = CBPTaskService::getList($sort['sort'], $filterData, false, $nav_params,
  ["ID", "WORKFLOW_ID","MODIFIED", "OVERDUE_DATE", "NAME","WORKFLOW_TEMPLATE_NAME","WORKFLOW_STARTED_BY","WORKFLOW_STARTED","DOCUMENT_NAME" ,"PARAMETERS"]
);
$nav->setRecordCount($res->selectedRowsCount());
while($row = $res->GetNext()) {
  $user = $row["WORKFLOW_STARTED_BY"];
  $rsUser = CUser::GetByID($user);
  $arUser = $rsUser->Fetch();
  $full_name = $arUser['NAME'].' '.$arUser['LAST_NAME'];
  $list[] = [
    'data' => [
      "ID" => $row['ID'],
      "NAME" => $full_name,
    ],
    'actions' => [
      [
        'text'    => 'Просмотр',
        'default' => true,
        'onclick' => 'document.location.href="?op=view&id='.$row['ID'].'"'
      ], [
        'text'    => 'Удалить',
        'default' => true,
        'onclick' => 'if(confirm("Точно?")){document.location.href="?op=delete&id='.$row['ID'].'"}'
      ]
    ]
  ];
}
$APPLICATION->IncludeComponent('bitrix:main.ui.grid', '', [
  'GRID_ID' => $list_id,
  'COLUMNS' => $columns,
  'ROWS' => $list,
  'SHOW_ROW_CHECKBOXES' => false,
  'NAV_OBJECT' => $nav,
  'AJAX_MODE' => 'Y',
  'AJAX_ID' => \CAjax::getComponentID('bitrix:main.ui.grid', '.default', ''),
  'PAGE_SIZES' =>  [
    ['NAME' => "5", 'VALUE' => '5'], 
    ['NAME' => '10', 'VALUE' => '10'], 
    ['NAME' => '20', 'VALUE' => '20'], 
    ['NAME' => '50', 'VALUE' => '50'], 
    ['NAME' => '100', 'VALUE' => '100'] 
  ],
  'AJAX_OPTION_JUMP'          => 'N',
  "AJAX_OPTION_STYLE"         =>"Y",
  'SHOW_CHECK_ALL_CHECKBOXES' => false,
  'SHOW_ROW_ACTIONS_MENU'     => true,
  'SHOW_GRID_SETTINGS_MENU'   => true,
  'SHOW_NAVIGATION_PANEL'     => true,
  'SHOW_PAGINATION'           => true,
  'SHOW_SELECTED_COUNTER'     => true,
  'SHOW_TOTAL_COUNTER'        => true,
  'SHOW_PAGESIZE'             => true,
  'SHOW_ACTION_PANEL'         => true,
  'ALLOW_COLUMNS_SORT'        => true,
  'ALLOW_COLUMNS_RESIZE'      => true,
  'ALLOW_HORIZONTAL_SCROLL'   => true,
  'ALLOW_SORT'                => true,
  'ALLOW_PIN_HEADER'          => true,
  'TOTAL_ROWS_COUNT'          => $nav->getRecordCount(),
  'FILTER'                    => $filterData,
  'AJAX_OPTION_HISTORY'       => 'N'
]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-03-29
@PetrPo

docks
Judging by the docks, this filter is just an auxiliary interface and you need to create a filter yourself after it

$filter = [];
$lAdmin = new CAdminUiList('report_list', null);
$lAdmin->AddFilter($ui_filter, $filter);

And the resulting $filter must be passed to getlist

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question