Signature
Import
- Component
- Plugin
To ensure optimal bundle sizes,
see Optimize build size.
Vue
About this widget
Theais-infinite-hits
widget displays a list of results with a “Show more” button at the bottom of the list.
As an alternative to this approach,
the infinite scroll guide
describes how to create an automatically scrolling infinite hits experience.
To configure the number of hits to show, use the ais-hits-per-page
or the ais-configure
widget.
See also: Searches without results.
Examples
Vue
Props
Whether to display a top banner when banner data is included within the
renderingContent
property from the Algolia API response.Vue
Whether to escape the raw HTML in the hits.
Vue
Enable the button to load previous results.
The button is only displayed if the routing option is enabled in
ais-instant-search
and users aren’t on the first page.
Override this behavior with slots.Vue
The CSS classes you can override:
ais-InfiniteHits
. The root element of the widget.ais-InfiniteHits-list
. The list of results.ais-InfiniteHits-item
. The list items.ais-InfiniteHits-banner
. The optional banner’s root.ais-InfiniteHits-banner-image
. The image element of the optional banner.ais-InfiniteHits-banner-link
. The optional anchor element of the optional banner.ais-InfiniteHits-loadPrevious
. The button to display previous results.ais-InfiniteHits-loadMore
. The button to display more results.ais-InfiniteHits-loadPrevious--disabled
. The disabled button to display previous results.ais-InfiniteHits-loadMore--disabled
. The disabled button to display more results.
Vue
Receives the items and is called before displaying them.
It returns a new array with the same “shape” as the original.
This is helpful when transforming, removing, or reordering items.The complete
results
data is also available,
including all regular response parameters and helper parameters (for example, disjunctiveFacetsRefinements
).If you’re transforming an attribute with the ais-highlight
widget,
you must transform item._highlightResult[attribute].value
.To prevent creating infinite loops,
avoid passing arrays, objects, or functions directly in the template.
These values aren’t referentially equal on each render,
which causes the widget to re-register every time.
Instead, define them in your component’s
data
option and reference them in the template.Vue
The widget caches all loaded hits.
By default, it uses its own internal in-memory cache implementation.
Alternatively, use
sessionStorage
to retain the cache even if users reload the page.You can also implement your own cache object with read
and write
methods.
This can be handy if you need to persist the data across sessions or if you expect the cached data to grow larger than the browser’s 5 MB allowed storage.Customize the UI
default
The slot to override the complete DOM output of the widget.When you implement this slot, none of the other slots will change the output, as the default slot surrounds them.Scope
-
items: object[]
. The records that matched the search. Each element ofitems
has the following read-only properties:__queryID
. The query ID (only ifclickAnalytics
istrue
).__position
. The absolute position of the item.
-
banner: object
. The banner data returned within therenderingContent
property from the Algolia API response. -
refinePrevious: () => void
. The function to load previous results. -
refineNext: () => void
. The function to load more results. -
isLastPage: boolean
. Whether it’s the last page. -
sendEvent: (eventType, hit, eventName) => void
. The function to sendclick
orconversion
events. Theview
event is automatically sent when this connector renders hits. To learn more, see theinsights
middleware.eventType: 'click' | 'conversion'
hit: Hit | Hit[]
eventName: string
-
insights: (method: string, payload: object) => void
: (Deprecated) Sends Insights events.-
method: string
. The Insights method to be called. Only search-related methods are supported:'clickedObjectIDsAfterSearch'
,'convertedObjectIDsAfterSearch'
. -
payload: object
. The payload to be sent.-
eventName: string
. The name of the event. -
objectIDs: string[]
. A list ofobjectID
s. -
index?: string
. The name of the index related to the click. -
queryID?: string
. The AlgoliaqueryID
found in the search response whenclickAnalytics: true
. -
userToken?: string
. A user identifier. -
positions?: number[]
. The position of the click in the list of Algolia search results. When not provided,index
,queryID
, andpositions
are inferred by the InstantSearch context and the passed object IDs:index
by default is the name of index that returned the passed object IDs.queryID
by default is the ID of the query that returned the passed object IDs.positions
by default is the absolute positions of the passed object IDs.
For more details about thepayload
property, see the Insights client documentation. -
-
loadPrevious
The slot to override the DOM output of the “Show previous” button.Scope
page: number
: the value of the current page.isFirstPage: boolean
: whether it’s the first page.refinePrevious: () => void
: the function to load the previous page.
Vue
banner
The slot to override the DOM output of the banner.Scope
banner: object
. The banner data returned within therenderingContent
property from the Algolia API response.
Vue
item
The slot to override the DOM output of the item.Scope
-
items: object
. A single hit with all its attributes. Each element ofitems
has the following read-only properties:__queryID
. The query ID (only ifclickAnalytics
istrue
).__position
. The absolute position of the item.
-
index: number
. The relative position of the hit in the list. -
insights: (method: string, payload: object) => void
. (Deprecated) sends Insights events.-
method: string
. The Insights method to be called. Only search-related methods are supported:'clickedObjectIDsAfterSearch'
,'convertedObjectIDsAfterSearch'
. -
payload: object
. The payload to be sent.-
eventName: string
. The name of the event. -
objectIDs: string[]
. A list of object IDs. -
index?: string
. The name of the index related to the click. -
queryID?: string
. The AlgoliaqueryID
found in the search response whenclickAnalytics: true
. -
userToken?: string
. A user identifier. -
positions?: number[]
. The position of the click in the list of Algolia search results. When not provided,index
,queryID
, andpositions
are inferred by the InstantSearch context and the passedobjectIDs
:index
by default is the name of index that returned the passedobjectIDs
.queryID
by default is the ID of the query that returned the passedobjectIDs
.positions
by default is the absolute positions of the passedobjectIDs
.
-
For more details about thepayload
property, see the Insights client documentation. -
Vue
loadMore
The slot to override the DOM output of the “Show more” button.Scope
page: number
. The value of the current page.isLastPage: boolean
. Whether it’s the last page.refineNext: () => void
. The function to load the next page.
Vue
HTML output
HTML
Click and conversion events
If theinsights
option is true
,
the ais-infinite-hits
widget automatically sends a click
event with the following “shape” to the Insights API when a user clicks on a hit.
JSON
sendEvent
function in your item
slot and send a custom click
event.
Vue
sendEvent
function also accepts an object as a fourth argument to send directly to the Insights API.
You can use it, for example, to send special conversion
events with a subtype.
Vue
Use strings to represent monetary values in major currency units (for example, ‘5.45’).
This avoids floating-point rounding issues, especially when performing calculations.