Retrieve the item that is clicked in a repeater

Is there a way to retrieve the item that is clicked in a repeater? I see that repeaters behave differently than tables but they are so much more aesthetically pleasing. I want to be able to perform a task based on the item that is clicked in a repeater.

1 Like

The same here, investigating like crazy

I am on it

1 Like

Repeaters are built using Containers. Add a click event to the container and continue from there.

export function container1_click(event, $w) {
	//Log the current item of the container.
	console.log($w("#dataset1").getCurrentItem());
}
4 Likes

Hey
Ok, it works when clicking in the container but if I want to have an add and a subtract button inside a repeater and when clicking the + button add some stuff and know the _id of the clicked item how to proceed?

Does the container click occur even if an object is clicked inside the container? Yes it does so first the container event occurs and then the element click event.

So I add the clicked item using getCurrentItem and store that in session on local or just in global variable. The issue then is that as you see below the Textinput field should be increased when clicking and when the user clicks they all got increased in all items inside the repeater. Any way around this?

1 Like

Thanks Shay for the perfect answer, I just added this event to any button or element inside the repeater.

export function plusButton_click(event, $w) {
	// Get clicked item
	let currentItem = $w("#dataset1").getCurrentItem();
	console.log("Choosen data record is: " + JSON.stringify(currentItem));
}

And I also discovered through you that Textinputs are not supported within a repeater element. Thanks a lot for always great support.

3 Likes

Thanks Andreas and Shay! Both contributions worked perfectly! Exactly what I needed.

1 Like

It is possible to put the result into a dynamic page (Profile Page)?

1 Like

What do you mean by putting the results?
Assuming you’re connecting the repeater to a dataset, you could have a button (or any other linkable element) wired to link to the item’s dynamic page.

1 Like

My current .getCurrentItemIndex() stays on 0 even if I click on a Item that isnt item 0

I got it working thanks after I figured out what I did wrong

export function container1_click(event, $w) {
Mine was  
export function container1_click(event) {

Old post, but just in case, use the event action of any items integrated to a repeater :

export function whateverElement_onClick(event) {
let $item = $w.at(event.context)
const data = $w("#repeater2").data;
let clickedItemData = data.find(item => item._id === event.context.itemId);

//console.log(clickedItemData._id) == "MY165ID"
}
1 Like

This code was the best for me as it’s easy to use clickedItemData to find the unique ID of the data row in the collection (clickedItemData_.id) that matches the item whose button was clicked in the repeater. Easy to go from there.