Signature
Import
About this widget
dynamicWidgets
is a widget that displays matching widgets,
based on the corresponding index settings and applied index rules.
You can configure the facet merchandising through the corresponding index setting.
To learn more, see Facet display.
Requirements
You must set the attributes for faceting and configure the facet order, either using the dashboard or with the API parametersattributesForFaceting
and renderingContent
.
All matching widgets mount after the first network request completes.
To avoid a second network request,
facets are set to ['*']
and maxValuesPerFacet
is set to 20 by default.
You can override these settings with the facets
and maxValuesPerFacet
parameters.
You must use InstantSearch.js v4.72.0 or later to use
dynamicWidgets
.Examples
Options
The CSS Selector of the DOM element inside which the widget is inserted.
A list of creator functions for all refinement widgets you want to conditionally display.
Each creator will receive a container and is expected to return a widget.
The creator can also return custom widgets created with connectors.Note that the returned widget needs to have an “attribute” or “attributes” argument,
as this will be used to determine which widgets to render in which order.
A creator function that is called for every attribute you want to conditionally display.
The creator will receive a container and attribute and is expected to return a widget.
The creator can also return custom widgets created with connectors.
A function to transform the attributes to render,
or using a different source to determine the attributes to render.
JavaScript
The facets to apply before dynamic widgets get mounted.
Setting the value to
['*']
will request all facets and avoid an additional network request once the widgets are added.The default number of facet values to request.
It’s recommended to have this value at least as high as the highest limit and showMoreLimit of dynamic widgets,
as this will prevent a second network request once that widget mounts.To avoid pinned items not showing in the result,
make sure you choose a
maxValuesPerFacet
at least as high as all the most pinned items you have.JavaScript
Customize the UI with connectDynamicWidgets
If you want to create your own UI of the dynamicWidgets
widget, you can use connectors.
To use connectDynamicWidgets
, 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 refinement values to display returned from the Algolia API.
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 widgets to dynamically add to the parent index.
You manually need to update their DOM position.
JavaScript
A function to transform the attributes to render,
or using a different source to determine the attributes to render.
JavaScript
The facets to apply before dynamic widgets get mounted.
Setting the value to
['*']
will request all facets and avoid an additional network request once the widgets are added.The default number of facet values to request.
It’s recommended to have this value at least as high as the highest limit and showMoreLimit of dynamic widgets,
as this will prevent a second network request once that widget mounts.To avoid pinned items not showing in the result,
make sure you choose a
maxValuesPerFacet
at least as high as all the most pinned items you have.JavaScript