E
E
Evgeniy Evsyukov2021-11-30 18:01:24
PHP
Evgeniy Evsyukov, 2021-11-30 18:01:24

How to make a filter with news.list?

I have a filter where cities are displayed, when clicking on the select, an ajax request is sent from the city id to the component

$(function(){
    $('.select-item').on('click', function(){
        var select = document.getElementById('someId');
    var opti = select.options[select.selectedIndex].value;
    
        $.ajax({
          method: "post",
          url: "/news.php",
          data: {
          "city_id": opti
          },
          success: function(data) {
          console.log(opti);
          $('.tranings__item').html(data);
          },
          error: function(er) {
          console.log(er);
          }
        });
    });
})

I do the arrfilter filter in the component, and I stuff $_POST['city_id'] into it, but it doesn’t work like that, tell me how to do it right?
component code
<? 
global $arrfilter;
$arrfilter = ['PROPERTY_CITY_INFO' => ['PROPERTY_VALUE_ID' => $_POST['city_id']]]; ?>
<?$APPLICATION->IncludeComponent(
  "bitrix:news.list",
  "",
  Array(
    "ACTIVE_DATE_FORMAT" => $arParams["LIST_ACTIVE_DATE_FORMAT"],
    "ADD_SECTIONS_CHAIN" => "N",
    "AJAX_MODE" => "Y",
    "AJAX_OPTION_ADDITIONAL" => "N",
    "AJAX_OPTION_HISTORY" => "N",
    "AJAX_OPTION_JUMP" => "N",
    "AJAX_OPTION_STYLE" => "N",
    "CACHE_FILTER" => "N",
    "CACHE_GROUPS" => "N",
    "CACHE_TIME" => $arParams["CACHE_TIME"],
    "CACHE_TYPE" => "A",
    "CHECK_DATES" => "N",
    "DETAIL_URL" => $arResult["FOLDER"].$arResult["URL_TEMPLATES"]["detail"],
    "DISPLAY_AS_RATING" => $arParams["DISPLAY_AS_RATING"],
    "DISPLAY_BOTTOM_PAGER" => "Y",
    "DISPLAY_DATE" => "N",
    "DISPLAY_NAME" => "Y",
    "DISPLAY_PICTURE" => "N",
    "DISPLAY_PREVIEW_TEXT" => "N",
    "DISPLAY_TOP_PAGER" => "N",
    "FIELD_CODE" => array("PREVIEW_PICTURE","={$arParams["LIST_FIELD_CODE"]}",""),
    "FILE_404" => $arParams["FILE_404"],
    "FILTER_NAME" => 'arrfilter',
    "HIDE_LINK_WHEN_NO_DETAIL" => "N",
    "IBLOCK_ID" => $arParams["IBLOCK_ID"],
    "IBLOCK_TYPE" => "-",
    "IBLOCK_URL" => $arResult["FOLDER"].$arResult["URL_TEMPLATES"]["news"],
    "INCLUDE_IBLOCK_INTO_CHAIN" => "N",
    "INCLUDE_SUBSECTIONS" => "Y",
    "MAX_VOTE" => $arParams["MAX_VOTE"],
    "MEDIA_PROPERTY" => $arParams["MEDIA_PROPERTY"],
    "MESSAGE_404" => $arParams["MESSAGE_404"],
    "NEWS_COUNT" => $arParams["NEWS_COUNT"],
    "PAGER_BASE_LINK" => $arParams["PAGER_BASE_LINK"],
    "PAGER_BASE_LINK_ENABLE" => "N",
    "PAGER_DESC_NUMBERING" => "N",
    "PAGER_DESC_NUMBERING_CACHE_TIME" => $arParams["PAGER_DESC_NUMBERING_CACHE_TIME"],
    "PAGER_PARAMS_NAME" => $arParams["PAGER_PARAMS_NAME"],
    "PAGER_SHOW_ALL" => "N",
    "PAGER_SHOW_ALWAYS" => "N",
    "PAGER_TEMPLATE" => $arParams["PAGER_TEMPLATE"],
    "PAGER_TITLE" => $arParams["PAGER_TITLE"],
    "PARENT_SECTION" => $arResult["VARIABLES"]["SECTION_ID"],
    "PARENT_SECTION_CODE" => "",
    "PREVIEW_TRUNCATE_LEN" => $arParams["PREVIEW_TRUNCATE_LEN"],
    "PROPERTY_CODE" => $arParams["LIST_PROPERTY_CODE"],
  ),
$component
);?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
no_one_safe, 2021-11-30
@no_one_safe

$arrfilter=array();
$arrfilter['PROPERTY_CITY_INFO']=$_POST['city_id'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question