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-selectis a native HTMLselectelement.ff-sortboxis 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:
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
Methods
Events
ff-sortbox-item
Properties
Events
Last updated
Was this helpful?