Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

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 parameters attributesForFaceting 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

string | HTMLElement
required
The CSS Selector of the DOM element inside which the widget is inserted.
Array<(container: HTMLElement) => Widget>
required
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.
(args: { attribute: string, container: HTMLElement }) => Widget
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.
function
A function to transform the attributes to render, or using a different source to determine the attributes to render.
JavaScript
['*']|[]
default:"['*']"
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.
number
default:20
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.
Then it’s a 3-step process:
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

string[]
The list of refinement values to display returned from the Algolia API.
JavaScript
object
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.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Instance options

object[]
required
The widgets to dynamically add to the parent index. You manually need to update their DOM position.
JavaScript
function
A function to transform the attributes to render, or using a different source to determine the attributes to render.
JavaScript
['*']|[]
default:"['*']"
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.
number
default:20
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

Full example

Last modified on July 22, 2026