Refresh data on the page which have been modified in collection

Question:
Refresh Data after closing lightbox

Product:
Wix Editor
Hello everyone

I have a main page and a lightbox which is displayed on this same page. (by calling it with a button). On this lightbox, I modify my data (stored in tables).
Someone on this forum (Thank you Mark_Hunte) has helped me to refresh the repeater or tables (from which data have been modify on the lightbox) on my main page after closing the lightbox. ( it workfs perfectly for the dataset changes. :+1:

But my fields on the main page are not modified even if the data are refreshed and have good values in the collection. My dataset is being refreshed : that is ok.
Even if i asked to be refreshed: it doesn’t retrieve last data upadted, but the penultimate update.
I would like that the data (already refreshed in the collection and the dataset and the table – Ok ) to be displayed in fields.

Here my code after closing the the lightbox:

wixWindowFrontend.openLightbox(‘Ajout SupplĂ©ments’)
.then(() => {

     wixData.query('Reservations')
    .eq("ReferenceReservation", $w('#NumResa').value)
    .find()
    .then(async (results) => {

        if (results.length > 0) {

            var Tarif = results.items.map(item => item.ARegler)
            var SUPP=results.items.map(item => item.totalSupplements)

            console.log ("Réservation trouvée : "+$w('#NumResa').value)
            console.log ("Total A REGLER à répercuter : "+ Tarif)
            console.log ("Total SUPPLEMENTS à répercuter : "+SUPP)
            

            //Rafraichir DATASET SUPPLEMENT
            $w('#SupplementsResa').setFilter(wixData.filter()
            .eq("ReferenceReservation", $w('#NumResa').value))
            $w('#SupplementsResa').refresh()


            //Rafraichir DATASET RESA EN COURS
            $w('#ResaEnCours').setFilter(wixData.filter()
            .eq("ReferenceReservation", $w('#NumResa').value))
            $w('#ResaEnCours').refresh()
        

        } else { 
            console.log("Pas de réservation correspondant au N°"+$w('#RefResa').value)
        }
    })      
})

Thank you for your help.


Pretty sure you should be doing the refresh before trying to query and update the repeater from the cms with your filters.

But saying that I cannot see why you are refreshing the dataset and then querying the cms.

I would expect you to then use the refreshed dataset.
This should save you Having to re filter and query the cms again.

wixWindowFrontend.openLightbox('Ajout Suppléments')
    .then(async () => {
        let numResaValue = $w('#NumResa').value;

        // == Refresh datasets  to latest CMS data
        await $w('#SupplementsResa').refresh();
        await $w('#ResaEnCours').refresh();

        //  == wait for dataset to be ready
        await $w('#SupplementsResa').onReadyAsync();
        await $w('#ResaEnCours').onReadyAsync();

        // Now use new data
        $w("#supplementsRepeater").data = $w("#SupplementsResa").getCurrentItems();
        
        $w("#resaRepeater").data = $w("#ResaEnCours").getCurrentItems();
      
 });

Not tested


1 Like

Thank you 
 again Mark :slight_smile:
i hadto adapt a little bit but everything ok

thanks

1 Like