populate items to repeater instantly after save

as the title describe i want populate the data that i just inserted into my data base right away after it being inserted

i tried a lot but it just not working , i have to refresh the page to be populated

this is my failure code :


ction getdata() {
    let query = wixData.query('visits')

    return query.limit(1000).find().then((resaults) => {
        console.log('getdata', resaults)
        return resaults.items
    });
}

$w.onReady(function () {

    let ii = $w("#dynamicDataset").getCurrentItem()

    $w("#dataset1").setFilter(wixData.filter()
        .eq("idPatient", ii._id));

    $w('#button2').onClick(() => {
        let toInsert = {
            "idPatient": ii._id,
            "quadrant": $w('#dropdown1').value,
            "toothnumber": $w('#input1').value,
            "premeasure": $w('#dropdown2').value,
            "detail": $w('#textBox1').value,
            "date": currentdate
        };

        wixData.insert("visits", toInsert)
            .then((results) => {
                let item = results; //see item below
            })
            .catch((err) => {
                let errorMsg = err;
            });
        $w('#textBox1').value = ''

        getdata().then((items) => {
            $w('#repeater1').data = items
        })

    })

});

any ideas???

Have you tried calling refresh on dataset after submit?

 $w("#myDataset").refresh() 

if you read my code
you will see that refresh () have no use in my code

@yaser1999yaser calling refresh is actually the best way to handle this. Since you are filtering the database you might have to refilter the data after refreshing the database. You could try abstracting your filter queries into a standalone function that is called once on page load and then again when a new item is added.

@amotor ok, if you are right , tell me
which data set are talking about :

  • the dynamic one
  • or the one that populate the repeater

@amandam

Hello. So first I would attempt what @amotor and @shio has suggested like so:.

getdata().then((items)=>{
remove the repeater data call and try
$w("#dataset1").refresh()

If that doesn’t work, I would suggest you drop using datasets and do all this work with wix-data. In general I would recommend choosing one path or the other, but you can test refresh first and see if it works this way

it works🎉
@amandam you are the best as always thanks