Skip to content
  1. Extras
  2. simpleFilters

simpleFilters

The package is installed in the standard way from the repository via the MODX 3 installer.

System settings

ParameterDescriptionDefault
sf_css_pathPath to JS file relative to site root{assets_url}components/simplefilters/js/web/default.min.js
sf_css_pathPath to CSS file relative to site root{assets_url}components/simplefilters/css/web/default.min.css

simpleFilters snippet

Outputs a resource list, filters, and loads all required scripts and styles.

Parameters

ParameterDescriptionDefault
&parentsParents for selection. Comma-separated IDs.Current resource
&resourcesResources for selection. Comma-separated IDs.
&showUnpublishedInclude unpublished resources0
&templatesResource template IDs, comma-separated
&whereInitial selection in JSON format
&sortbySort fieldmenuindex
&sortdirSort directionASC
&limitItems per page10
&includeTVsTV names to include in output, comma-separated
&tvPrefixPrefix for TV fields in resource chunktv_
&msPrefixPrefix for MiniShop3 product fieldsms_
&msoPrefixPrefix for MiniShop3 product optionsmso_
&hideOneHide filters with a single value1
&checkEmptyCompute result for each filter value (heavier query)0
&filtersFilter list as field1:type1,field2:type2,field3:type3
&fseparatorFilter value separator in URL_
&modeand — all conditions must match, or — at least oneor
Templating
&tplResource output chunk
&tplWrapperWrapper chunk for full outputsf_wrapper
&tplFilterChunk for checkbox/radio filter blocksf_filter
&tplFilterRowChunk for checkbox filter rowsf_filter_row
&tplFilterRadioRowChunk for radio filter rowsf_filter_radio_row
&tplFilterSelectChunk for select filter blocksf_filter_select
&tplFilterSelectRowChunk for select option rowsf_filter_option_row
&tplFilterSliderChunk for slider filter blocksf_filter_slider
&tplSelectedChunk for selected filter blocksf_selected_filter
&tplSelectedRowChunk for selected filter rowsf_selected_row
Pagination
&tplPaginationWrapperPagination wrapper chunksf_pagination
&tplPaginationPage link chunksf_page
&tplPaginationFirstFirst page link chunksf_page_first
&tplPaginationLastLast page link chunksf_page_last
&tplMoreButton"Load more" button chunksf_morebutton

Configuring filters

In &filters use these prefixes:

  • Resource field — no prefix
  • TV — tv_
  • MIGX field — migx_
  • MiniShop3 product field — ms_
  • MiniShop3 product option — mso_

Types:

  • Checkbox — checkbox or leave empty
  • Dropdown — select
  • Slider — slider
  • Radio — radio

Example filter list:

&filters=`
    parent:select,
    ms_vendor_id:select,
    ms_price:slider,
    tv_instock:slider,
    migx_chars_Height:slider:title|value,
    ms_color,
    ms_tags:select
`

MIGX fields use the format:

migx_[tv name]_[parameter name]:[filter type]:[label field]|[value field]

For a MIGX TV chars with config:

json
[{"fields":
  [
    {"field":"title", "caption":"Parameter"},
    {"field":"value", "caption":"Value"}
  ]
}]

To create a slider filter for "Height":

migx_chars_Height:slider:title|value

Checkbox filter for "Purpose":

migx_chars_Purpose:title|value

&where parameter

Supports one parameter/value. Works only with resource and MiniShop3 product tables (field names as in the database, no prefixes).

DescriptionExample
New items only'where' => '{"new":"1"}'
Products with price > 2000'where' => '{"price:>":"2000"}'
Resources with "sale" in longtitle'where' => '{"longtitle:like":"sale"}'

Templating

Default chunks use Fenom (requires pdoTools); standard syntax is also supported.

You can use custom chunks per filter via &tplFilter_parameter and &tplFilterRow_parameter.

Example for a custom filter by ms_tags:

&tplFilter_ms_tags=`your_block_chunk`
&tplFilterRow_ms_tags=`your_row_chunk`

Filter block labels are set via lexicon keys sf_filter_filter_name (or in the plugin).

JavaScript

To submit the form use sf.submit:

js
sf.submit();

After data refresh the sfilters event fires:

js
document.addEventListener('sfilters', (e) => {
    // console.log(e);
});

System events

All events receive an array $data.

EventDescription
sfOnGetIdsFired after initial collection of displayed resource IDs. You can add a resource by ID or replace the whole set.
sfOnGetFilterValuesFired after filter values are built. Receives array of values (e.g. to sort), filter name and type.
sfOnBeforeCreateFilterRowFired when a filter row is created. You can change labels, values, etc.
sfOnBeforeCreateFilterFired when a filter block is created. You can change block title, slider range, etc.
sfOnCheckResourceFired when checking a resource against a selected filter value. Receives resource id, filter name, value. To include the resource, set $data['result'] = true;

The simpleFilters plugin is included with examples.