Signature
Import
About this widget
ThehitsPerPage
widget displays a menu for letting users change the number of displayed hits.
If you only want to configure the number of hits per page without displaying a widget,
you can use the configure
widget with the hitsPerPage
search parameter.
Examples
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.The list of available options, with each item:
label: string
. The label to display in the option.value: number
. The number of hits to display per page.default: boolean
. The default hits per page on first search.
JavaScript
The CSS classes you can override:
root
. The root element of the widget.select
. Theselect
element.option
. Theoption
elements of theselect
.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript
HTML output
HTML
Customize the UI with connectHitsPerPage
If you want to create your own UI of the hitsPerPage
widget, you can use connectors.
To use connectHitsPerPage
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
Rendering options
The list of items the widget can display, with each item:
label: string
. The label to display in the option.value: number
. The number of hits to display per page.isRefined: boolean
. Indicates if the item is the current refined value.
JavaScript
Whether the search can be refined.
JavaScript
Sets the number of hits per page and triggers a search.
JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
The list of available options, with each item:
label: string
. The label to display in the option.value: number
. The number of hits to display per page.default: boolean
. The default hits per page on first search.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript