ais-sort-by
<ais-sort-by :items="object[]" // Optional parameters :transform-items="function" :class-names="object" />
1
2
3
4
5
6
7
8
9
import { AisSortBy } from 'vue-instantsearch';
// Use 'vue-instantsearch/vue3/es' for Vue 3
export default {
components: {
AisSortBy
},
// ...
};
1. Follow additional steps in Optimize build size to ensure your code is correctly bundled.
2. This imports all the widgets, even the ones you don’t use. Read the Getting started guide for more information.
About this widget
The ais-sort-by
widget displays a list of indices, allowing a user to change the way hits are sorting (with replica indices).
Another common use case for this widget is to let users switch between different indices.
For this widget to work, you must define all indices that you pass down as options as replicas of the main index.
Examples
1
2
3
4
5
6
7
<ais-sort-by
:items="[
{ value: 'instant_search', label: 'Featured' },
{ value: 'instant_search_price_asc', label: 'Price asc.' },
{ value: 'instant_search_price_desc', label: 'Price desc.' },
]"
/>
Props
Parameter | Description | ||
---|---|---|---|
items
|
type: object[]
Required
The list of indices to search in, with each item:
|
||
Copy
|
|||
transform-items
|
type: function
default: items => items
Optional
Receives the items and is called before displaying them. Should return a new array with the same shape as the original array. Useful for transforming, removing, or reordering items. In addition, the full When using an array, take steps to avoid creating infinite loops. When you use an array as a prop, it causes the widget to re-register on every render, and this can sometimes cause these infinite loops. |
||
Copy
|
|||
class-names
|
type: object
default: {}
Optional
The CSS classes you can override:
|
||
Copy
|
Customize the UI
Parameter | Description | ||
---|---|---|---|
default
|
The slot to override the complete DOM output of the widget. Note that when you implement this slot, none of the other slots will change the output, as the default slot surrounds them. Scope
Where each item is an
|
||
Copy
|
HTML output
1
2
3
4
5
6
7
<div class="ais-SortBy">
<select class="ais-SortBy-select">
<option class="ais-SortBy-option" value="instant_search">Featured</option>
<option class="ais-SortBy-option" value="instant_search_price_asc">Price asc.</option>
<option class="ais-SortBy-option" value="instant_search_price_desc">Price desc.</option>
</select>
</div>