Hi,
So I have a dataset that is connected to a repeater, and I want to get the item index of the repeater item.
So I tried the following code:
export function container3_click(event, $w) {
console.log(String($w("#dataset1").getCurrentItemIndex()));
}
But no matter wich item I click, it always returns 0. I want it to return the item index of that item in the database.
HI
Indeed, the item index does not change when clicking of different items.
In the following code, one can see that $w(“#dataset1”).onCurrentIndexChanged handler is never called.
But $w(“#dataset1”).getCurrentItem(); inside $w(“#container1”).onClick returns the correct item. So you could use that to retrieve the item id in the database.
// KO never called
$w("#dataset1").onCurrentIndexChanged( (index) => {
console.log("index : " + index);
});
$w("#container1").onClick( (event, $w) => {
// OK returns the clicked item : a, b...
let clickedItemData = $w("#dataset1").getCurrentItem();
// KO stays to 0
let clickedItemId = $w("#dataset1").getCurrentItemIndex();
console.log("clickedItemData : " + clickedItemData["mail"] + ", clickedItemId = " + clickedItemId);
});
The dataset exists on the page and does not change based on which repeater item is clicked. However, the repeater will assign values from the connected dataset to each item containter. You can get the ID of the collection item like this:
export function container1_click(event, $w) {
console.log(event.context.itemId);
let itemId = event.context.itemId;
}
I hope that helps,
Yisrael