How to refresh repeater after submit

How do I refresh my repeater content on the page after a new record is submitted? I used the following code but the repeater is not refreshing with the new item. What am I doing wrong?

export function appcreateButton_click ( event ) {
$w ( ‘#newappBox’ ). hide ();
$w ( ‘#newappButton2’ ). show ();
$w ( “#dataset1” ). refresh ()
. then ( () => {
console . log ( “Done refreshing the dataset” );
} );

1 Like

Hello @_eric , are you connecting your repeater manually (through elements) or by code? Because if it is manually connected, it should refresh the repeater as soon as the dataset is refreshed.

Otherwise, you should assign a new data to the repeater using the data property, like so:

$w("#myRepeater").data = newData

Let me know!

Hi Bruno,

The repeater is currently connected through a dataset that lives on the page. I have a form, that is also connected to the dataset.

I would like for the added record to automatically populate to the repeater upon submission.

How would you suggest I get that result? Currently, I have to refresh the browser page for the data to populate into the repeater, which is not what I want.

Anyone?

@_eric I would guess that you are trying to refresh the dataset before it is really updated, because you are not using code. That’s why it is not working. I tried using a Hook to capture the dataset change but could not do it, I guess inserting items through a form uses suppressHooks that cannot be changed.

So the solution I found was putting a 2 seconds delay on the .refresh() method call, like this:

let debounce
export function appcreateButton_click(event) {
    $w('#newappBox').hide();
    $w('#newappButton2').show();
    clearTimeout(debounce)
    debounce = setTimeout(async () => {
        await $w('#dataset2').refresh()
        console.log('Refreshed!')
    }, 2000)
}

@bwprado You are amazing!! That did the job. It needed the await function. THANK YOU SO VERY MUCH!!!