How to create a dynamic carousel item count (displayed in the badge) where the items in the carousel are controlled by a repeater pulling its data from a data resource.
Before you begin
Role required: workspace_admin or ui_builder_admin
This procedure uses
UI Builder components to create dynamic, interactive layouts. For more information on how to configure components, see:
Table 1. Components used in this procedure
| Component |
Documentation links |
| Carousel |
|
Procedure
-
Set up Carousel to use a repeater pulling its data from a data resource.
-
To create an object that determines the badge properties, open the page's Client state parameters dialog.
-
Replace the Name with badgeConfigState, and from the Type dropdown, choose JSON.
-
Hover over the Initial value field box and select Edit.
-
Choose the JSON type object from the dropdown.
-
Select Add property and add the badge color, label, and variant properties.
-
Select Apply to return to the Edit client state parameters dialog.
-
Close the dialog.
Later, you will use a script to update this object's properties after the data resource loads.
-
To set the badge config to the object just created, in the Content tree, select the Carousel component.
-
On the Config tab for your Carousel component, hover over the Badge configuration property and select the Bind data or use scripts icon.
-
In the Bind data to Badge configuration dialog, select the data type Client states.
-
Select badgeConfigState (3), and to add it to the data output area, select the up arrow icon.
-
Select Apply.
The badgeConfigState parameter should be added to the Carousel Badge configuration.
-
Open the Edit client script dialog by selecting Add a new
Edit client script.
-
To create a client script that updates the badgeClientState "label" parameter value to the number of items in the Carousel, enter:
api.setState(`badgeConfigState`,
{...api.state.badgeConfigState, "label": `count: ${api.data.look_up_multiple_records_1.results.length}`});
-
Add an event to the data resource so that your client script triggers whenever the data resource is updated.
-
In the bottom left, select the data resource .
-
Select Add event mapping, select Data Fetch Succeeded, and select Continue.
-
Select Add handler, scroll down, and select the new client script you created, and select Continue.
-
When to trigger should be set to Always.
-
Select Continue.
-
Select Add and close the Edit dialog.
-
In the upper right corner, select .
The Title of your carousel should have a badge count followed by the number of carousel items.