For the complete documentation index, see llms.txt. This page is also available as Markdown.

Sortbox

Let shoppers sort products with native or custom dropdowns.

Documentation

Overview

With the sort box element you can change the order in which products are displayed. There are two kinds of sort boxes:

  • ff-sortbox-select is a native HTML select element.

  • ff-sortbox is a custom-built dropdown element.

Both can be used with or without customization.

Sort box elements are populated with the sortItems portion from the FactFinder search response. Inside the HTML template of the sort box item, you therefore have access to all those data fields (DescribedSortItem).

Native HTML select (ff-sortbox-select)

The ff-sortbox-select element displays a native HTML select element.

<ff-sortbox-select></ff-sortbox-select>
<ff-sortbox-select>
    <option>{{description}}</option>
</ff-sortbox-select>
<ff-sortbox-select>
    <select class="example-class">
        <option>Sort by: {{description}}</option>
    </select>
</ff-sortbox-select>

Rendered HTML

When set up like in the last example above, the rendered HTML could look like this.

<ff-sortbox-select>
    <select class="example-class">
        <option>Sort by: Title A-Z</option>
        <option>Sort by: Title Z-A</option>
        <option>Sort by: Relevance</option>
    </select>
</ff-sortbox-select>

Custom-built dropdown (ff-sortbox)

The ff-sortbox element is a custom-built dropdown. If you do not define any ff-sortbox-item templates, items will default to <ff-sortbox-item>{{description}}</ff-sortbox-item>.

If you do specify ff-sortbox-item templates, you may define an individual template for each item in the sortItems list of the FactFinder response.

FactFinder provides each item with a name and an order field. When you combine them, you get a unique identifier that you can use in the key attribute of the ff-sortbox-item template.

You do not have to specify templates for all sort item types. Only define those that you wish to deviate from the default.

Available keys are as follows:

Available keys
Key
Description

default.template

This is the fallback template for all options that have no other template defined.

ff.relevance

FactFinder always returns an option to sort by relevance.

{name from FactFinder response}.asc

An option as specified in FactFinder in ascending order. (e.g. Price.asc, Title.asc)

{name from FactFinder response}.desc

An option as specified in FactFinder in descending order. (e.g. Discount.desc, Title.desc)

Inside the ff-sortbox-item, you can access the sort option name with {{description}}.

show-selected / show-selected-first

By default, the selected sort option will disappear from the dropdown list and appear in the static container of the element. Setting the show-selected attribute means the selected option remains part of the available options in the dropdown list.

When show-selected is set, you can additionally set show-selected-first to make the selected option appear as the first item in the dropdown. Without show-selected, the setting of show-selected-first has no effect.

collapse-onblur

Set collapse-onblur="true" to collapse the dropdown when the element loses focus. It defaults to false.

Rendered HTML

When set up like in the example above, the rendered HTML could look like this.

Example

Use a fixed static label by hiding the selected container. Add a click handler that toggles the sortbox.

Demo

Try the Sortbox demo.

API code

ff-sortbox

Properties

Properties
Name
Description

items (Array) (default: empty)

Data from FactFinder. Set this through JavaScript only.

opened (Boolean) Options: true, false (default: false)

Determines whether the sort box is open.

show-selected (String) Options: "true", "false" (default: "false")

Shows the selected sort option in the dropdown.

show-selected-first (String) Options: "true", "false" (default: "false")

Displays the selected sort option first. Requires show-selected="true".

collapse-onblur (String) Options: "true", "false" (default: "false")

Closes the dropdown when it loses focus.

Methods

Methods
Name
Description

toggle(collapse?: Boolean)

Opens or closes the element.

show()

Opens the dropdown.

hide()

Closes the dropdown.

Events

Events
Name
Description

dom-updated

Fires after the element receives data and renders its templates.

ff-sortbox-item

Properties

Properties
Name
Description

sort-item (Object) (default: empty)

Data from FactFinder.

Events

Events
Name
Description

dom-updated

Fires after the element receives data and renders its templates.

Last updated

Was this helpful?