getCurrentItem Always Returns The First Item

I have a repeater that is bound to a dataset. The dataset is read / write. I have a button that is displayed on each item in the repeater. I have added a click handler to the button in the repeater. In the handler, I am calling getCurrentItem() of the dataset, but no matter which item I click on, getCurrentItem() returns the first item in the dataset. How do I get the actual current item?

export async function pickupButton_click(event) {
    console.log($w("#dataset1").getCurrentItem()); // Always returns the first element in         the dataset, no matter which element is clicked on
}
1 Like

@zackgreenberg To have getCurrentItem return the data of the row which you clicked, you need to use the at() function . You would then use $item instead of the typical $w when you reference a repeater item.

export async function pickupButton_click(event) {
    let $item = $w.at(event.context);
    console.log($item("#dataset1").getCurrentItem()); 
}

Worked perfectly, thanks so much.

Hi guys, I’m having the same issue, the difference is im not using a repeater, I just want to retrieve a specific element from a dynamic dataset. I’m trying to calculate an age based on date of birth, im trying to retrieve the date of birth from the collection but im only getting the date of the first row. The code you used is showing “context” as undefined. Thanks for your help.

Hi Omar,

The code in the post above specifically allows you to work with a repeater item.

Do you have a table on your page? Posting your current code would give you a better chance of being helped.

hey guys ,
I am using Boolean from my database to get text in my repeater . But I am getting same result(N/C) in every container for both input (true/false) . Here is my code …

export function text29_viewportEnter(event) {
let novelstatus = $w( “#dataset2” ).getCurrentItem().novelstatus;
if (novelstatus === true ) {
$w( “#text29” ).text = “Completed” ;}
else { $w( “#text29” ).text = “N/C” ;}
}

Please open up a new thread.

Read more about the Community Guidelines .

1 Like

@nabinpauudel664 The key to getting this right where you’re accessing particular rows of a repeater, along with the data associated with it, is using the at() function . Give the following a try:

export function text29_viewportEnter(event) {
   let $item = $w.at(event.context);
   let novelstatus = $item("#dataset2").getCurrentItem().novelstatus;
   if (novelstatus === true) {
       $item("#text29").text = "Completed";
   } else { 
       $item("#text29").text = "N/C";
   }
}
1 Like