How to reset repeater results to its first item only ?

$w("#resetButton").onClick((event) => {
        let somedata = $w('#somedatainput').value;
        wixData.query("dataset1")
            .eq("field1", somedata)
            .find()
            .then(results => {
                $w('#repeater1').data = results.items;
            });
        $w('#resetButton').hide();
        $w('#searchButton').show();
        $w('#searchButton').enable();
    });

I need to display only first item of result but I am not able to figure it out how!! Please if anyone can help… ! :sweat:

You are directly using ‘items’ which is not only the first item of your database (if you have more than 1 item in your database).

There are different ways to do this and I will show you two example:

First Way:
Create an array and add the first index into this array. So repeater only gonna have the first index.

$w("#resetButton").onClick((event) => {
    let somedata = $w('#somedatainput').value;

    wixData.query("dataset1")
        .eq("field1", somedata)
        .find()
        .then(results => {
            $w('#repeater1').data = [results.items[0]];
        });

    $w('#resetButton').hide();
    $w('#searchButton').show();
    $w('#searchButton').enable();
});

Second Way:
Use .limit() API inside your wixData query so you will only get 1 item from the database when you query.

$w("#resetButton").onClick((event) => {
    let somedata = $w('#somedatainput').value;

    wixData.query("dataset1")
        .eq("field1", somedata)
        .limit(1)
        .find()
        .then(results => {
            $w('#repeater1').data = results.items;
        });

    $w('#resetButton').hide();
    $w('#searchButton').show();
    $w('#searchButton').enable();
});

Note
If this your goal is removing all items from the repeater except first item than you can use current array data so it will be faster.

$w("#resetButton").onClick((event) => {
    let somedata = $w('#somedatainput').value;

    let filteredData = $w('#repeater1').data.filter((item) => {
        return item['field1'] === somedata;
    })[0]

    $w('#repeater1').data = [filteredData]

    $w('#resetButton').hide();
    $w('#searchButton').show();
    $w('#searchButton').enable();
});