I’m facing an issue with dynamic numbering in a repeater when applying filters in Wix Studio. The numbering works fine initially, but once a filter is applied, the numbers don’t update correctly, they skip, or don’t match the filtered dataset.
Has anyone encountered this before? Is there a reliable workaround or code solution to make the numbering re-generate properly after filtering?
Hi @Rob Here’s the code that implement in the editor site:
// // Access the repeater and handle each item// $w(‘#repeater1’).onItemReady(($item, itemData, index) => {// const richText = $item(‘#text45’);
// // Get the HTML content of the Rich Text element// let richTextHtml = richText.html;
// // Check if there are any links ( tags) in the HTML content// if (richTextHtml.includes('<a ')) {// // Update the link target to ‘_self’ to ensure links open in the same window// richTextHtml = richTextHtml.replace(/<a /g, '<a target=“_self” ');
// // Set the updated HTML back to the Rich Text element// richText.html = richTextHtml;// }// });
// let authorFullname = “Dulanga Weerakoon, Vigneshwaran Subbaraju, Joo Hwee Lim, Archan Misra”;// let authors = authorFullname.split(“,”);// console.log(authors);// // Run when the repeater is ready// $w(“#repeater1”).onItemReady(($item, itemData, index) => {// console.log(itemData); // Log item data to inspect// // Check if the author has published based on the isPublished field// if (itemData.isPublished) {// $item(“#button1”).show(); // Show the button if published// } else {// $item(“#button1”).hide(); // Hide the button if not published// }// });// });
// $w.onReady(function () {// // Make sure to use the correct ID of the Rich Text element// $w(‘#richTextBox1’).style.backgroundColor = “transparent”;// });
// $w(‘#richTextBox1’).onBlur((event) => {
// })
// $w(‘#richTextBox1’).onChange((event) => {
// })
// $w(“#dataset1”).onReady( () => {// let item = $w(“#dataset1”).getCurrentItem();// if (item.Text) {// $w(“#text48”).show();// } else {// $w(“#text48”).collapse();// $w(“#text48”).hide();// }
// // if (item.URL) {// // $w(“#text50”).show();// // } else {// // $w(“#text50”).collapse();// // $w(“#text50”).hide();// // }// } );import wixData from “wix-data”;
$w.onReady(() => {// Assuming your dataset is connected to the repeater$w(“#dataset1”).onReady(() => {let items = $w(“#dataset1”).getItems(0, $w(“#dataset1”).getTotalCount()).then((result) => {let total = result.items.length;$w(“#repeater2”).onItemReady(($item, itemData, index) => {// Add numbering dynamically$item(“#text59”).text = (index + 1).toString();});});});});
$w.onReady(() => {$w(“#repeater2”).onItemReady(($item, itemData) => {const authors = itemData.authorsArray;const doi = itemData.doi;const maxButtons = 9;
let buttonIndex = 0; // Tracks which button to populate
for (let i = 0; i < authors.length; i++) {
if (authors[i].link) { // Only show authors with a link
const buttonId = `#authorButton${buttonIndex}`;
$item(buttonId).label = authors[i].name;
$item(buttonId).link = authors[i].link;
$item(buttonId).target = "_blank";
$item(buttonId).expand();
buttonIndex++;
}
}
// Hide remaining buttons
for (let j = buttonIndex; j < maxButtons; j++) {
$item(`#authorButton${j}`).collapse();
}
if (!doi || doi === "") {
$item("#button2").collapse();
}
});});