Views: 14943
Last Modified: 12.09.2014

In order to perform sorting the parameters ELEMENT_SORT_FIELD and ELEMENT_SORT_ORDER must be submitted to the component news.list or catalog.section.

The sorting can be made by standard fields. To do so, use the list provided below:

  • id - element ID;
  • sort - sorting index;
  • timestamp_x - modification date;
  • name - name;
  • active_from or date_active_from - element start date;
  • active_to or date_active_to - element end date;
  • status - code of the element status in the document flow;
  • code - mnemonic code of the element;
  • iblock_id - numerical code of the information block;
  • modified_by - code of the last modifying user;
  • active - indicator of activity of an element;
  • show_counter - number of shows of an element (recorded by the function CIBlockElement::CounterInc);
  • show_counter_start - time of first show of an element (recorded by the function CIBlockElement::CounterInc);
  • shows - averaged number of shows (number of shows/duration of a show);
  • rand - random order;
  • xml_id or external_id - external code;
  • tags - tags;
  • created - creation time;
  • created_date - creation date with no regard to the time;
  • cnt - number of elements (only if grouping parameters are set).

Note: The fields active_from and active_to are out of date.

You can also sort by the properties that you create for an information block element:

  • property_<PROPERTY_CODE> - by the value of the property with a numeric or mnemonic code PROPERTY_CODE (e.g., PROPERTY_123 or PROPERTY_NEWS_SOURCE).
  • propertysort_<PROPERTY_CODE> - by the sorting index of the property value option. Only for List properties.
  • catalog_<CATALOG_FIELD>_<PRICE_TYPE> - by the field CATALOG_FIELD (may be PRICE or CURRENCY) from the price with the format PRICE_TYPE (e.g., catalog_PRICE_1 or CATALOG_CURRENCY_3). Sorting must have the following format: CATALOG_(PRICE or CURRENCY)_type-of-price-ID.
  • catalog_QUANTITY - sorting by quantity.
  • PROPERTY_<PROPERTY_CODE>.<FIELD> - by field value of the element indicated as binding. PROPERTY_CODE - a mnemonic or symbol property code of the type element binding. FIELD can take the following values:
    • ID
    • TIMESTAMP_X
    • MODIFIED_BY
    • CREATED
    • CREATED_DATE
    • CREATED_BY
    • IBLOCK_ID
    • ACTIVE
    • ACTIVE_FROM
    • ACTIVE_TO
    • SORT
    • NAME
    • SHOW_COUNTER
    • SHOW_COUNTER_START
    • CODE
    • TAGS
    • XML_ID
    • STATUS
  • PROPERTY_<PROPERTY_CODE>.PROPERTY_<PROPERTY_CODE2> - by the property value of the element indicated as binding. PROPERTY_CODE - mnemonic or symbol property code of the type element binding. PROPERTY_CODE2 - property code of the related elements.
  • HAS_PREVIEW_PICTURE and HAS_DETAIL_PICTURE - sorting by picture availability.

Note: The catalog properties are available only if the module Commercial catalog is in place.

The sorting type is indicated according to the list:

  • asc - in ascending order;
  • nulls,asc - in ascending order with empty values in the beginning of the selection;
  • asc,nulls - in ascending order with empty values in the end of the selection;
  • desc - in descending order;
  • nulls,desc - in descending order with empty values in the beginning of the selection;
  • desc,nulls - in descending order with empty values in the end of the selection.

The simplest way to submit new sorting parameters to a component consists in using the query $_GET and transmission of the relevant variables.

Also you can use $_SESSION and enter variables into array of variables of the session. For example, you have to make links or buttons (name, price, bestseller, and/or delivery date) to sort the goods in a catalog section (we use the compound component catalog). After we have copied the template, we open the file section.php and make the following modifications to it before connecting the component bitrix:catalog.section:

<?if ($_GET["sort"] == "name" || 
              $_GET["sort"] == "catalog_PRICE_3" ||
              $_GET["sort"] == "property_PRODUCT_TYPE" ||
              $_GET["sort"] == "timestamp_x"){
		$arParams["ELEMENT_SORT_FIELD"] = $_GET["sort"];
		$arParams["ELEMENT_SORT_ORDER"] = $_GET["method"];
	}else{}?>

This code is required to change the sorting parameters in a component. Next, open the file template.php of the component catalog.section and add sorting management references:

<p class="sort">Sorting:
	<a <?if ($_GET["sort"] == "name"):?> class="active" <?endif;?> href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=name&method=asc">title</a> 
	<a <?if ($_GET["sort"] == "catalog_PRICE_3"):?> class="active" <?endif;?> href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=catalog_PRICE_3&method=asc">price</a> 
	<a <?if ($_GET["sort"] == "property_PRODUCT_TYPE"):?> class="active" <?endif;?> href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=property_PRODUCT_TYPE&method=desc">bestseller</a> 
	<a <?if ($_GET["sort"] == "timestamp_x"):?> class="active" <?endif;?> href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=timestamp_x&method=desc">delivery date<</a>
</p>

This sorting can be executed without reloading the page by using jQuery.



Courses developed by Bitrix24