Adressing first item of a repeater

Hi, I have a repeater with 5 items. All of the items can be expanded by clicking on them. When the page is loaded, the items are all collapsed.

However, the first item shall already be expanded when the page is loaded and the repeater is ready.

Any idea how I can do this?

Basically this should be something like…

dataset.onReady(() => {
      repeater.onItemReady (() => {
	repeater.FirstItem.expand();
      });
    });    

Thank you very much for your help!

$w.onReady(() => {
const dataset = $w('#dataset1'), repeater = $w('#repeater1');
dataset.onReady(()=>{
repeater.onItemReady(($item, itemData, index) => {
if(index === 0){
$item('#container1').expand();
}
});
});
});

Thank you very much! This works!

J.D., can you help me with another detail? How can I retrieve data from the dataset of that item? I would like to get the title of the item and store it in the variable myTitle:

const data = repeater.data;
let ItemData = data.filter(item => item === $item)
let myTitle = ItemData[0].title;

Thank you again very much!

@jg1 I’m not sure what you’re trying to do. Please elaborate.

@jg1 I think you are trying to get the context from items in the repeater, for that you need an input, either a Click or a MouseIn event.

This is a function that retrieves the clickedItem, you just need to pass the event and the data from the repeater:

function getSelectedItemData({ context }, data) {
    return data.find(item => item._id === context.itemId)
}

This is the application:

$w("#itemRepeaterSearchCostumer")
    .onClick(event => {
        let data = $w("#repeaterSearchCostumer").data
        let clickedItem = getSelectedItemData(event, data)
        selectedCostumer = clickedItem
        fillCostumer()
    })

@J.D I wanted to get the data of a specific data field of the first item. In my example the data from the “title” data column.

I managed to acchieve what I wanted with this. Is this ok or is there a better way?

const data = repeater.data;
      let ItemData = data.filter(item => index === 0)
      let myTitle = ItemData[0].title;

@Bruno Prado: I wanted to adress the data of the first item in the repeater, not the clicked one. Thank you.