Save and refresh repeater

Hi i have question. When i want to save what i change in repeater my funcion seems to save and refresh only inside repeater. How can i change it to save whats in repeater but refresh whole dataset because its sorted. I want to refresh sorting after save.

export function button71_click(event, $w) {
return $w(“#dataset1”).save()
.then(() => {
// Data is saved now refresh the dataset1
$w(“#dataset1”).refresh();
})
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
});
}

Hi,

If I understand you correctly, on your page site you had a repeater that connected to a dataset.

  • You set a sort() on your dataset (I believe you have set it in the dataset’s setting), and moreover your dataset supposed to be in read & write mode because you wish to present data and update

  • You had an onClick() event handler on button71 and at the handler you save the changes and refresh the dataset in order to sort again the data in the repeater.

If this is the case your function supposed to work, otherwise please be more specified while describing the issue.

In addition, please send us a URL to your site and specified the page name so we can inspect.

Best,
Sapir

Thank You for helping.
it work save but doesnt want to refresh.

https://www.ceglarnia.com/dekorac

user: misiewicz@hpworldwide.pl
info

Is page to write itinerary of wedding. People write start time and what is happening and save. Dataset is sorted by hour of start (first input) when i save and go again to site its sorted so it works. It seems like button refresh before save. Is it possible?

HI Did You have some time to see what is going on with this refresh :slight_smile: Thanks Kris

Hi,
What is the name of page?


Thanks,
Sapir

K Przebieg Imprezy

the same problem i have with Lista Gisci site
https://www.ceglarnia.com/lista-gosci

it seems like refresh only one item not entire dataset because of (event, Sw) is it possible?

Hi, my suggestion is:

  1. Cancel the sort that you have done with the editor and instead create your own sort function at the page site. In the the function use setSort( ) on the dataset.
function sort(){
// write the setSort() function
}

Here you can watch how to do it with code.

  1. In order to first sort the dataset, at the onReady() function, add an onReady() event handler to the dataset and summon the sort() function in the handler.
$w.onReady( () => {
  $w("#myDataset").onReady( () => {
      .then( () => {
        sort();
      } )
  } );
  1. Add an export function to your dataset - onAfterSave() and summon the sort() function.
    This function will be triggered each time you save an item in your dataset, as a result your sort function will also be activated.
    Here you can read more about this function.
export function dataset_afterSave() {
 sort()
}

Best of luck!
Sapir

ok. I was thinking of go to some page “reload” and than back. But its strange because i’m almost sure few weeks ago it worked and it stopped working suddenly. I will try Your solution.
Thank You so much for Your time. Chris

Sorry its me again because something really strange is happening. My funcion sortuj() i checked works but afterSave doesnt. You can see it in “Lista Gosci” page.
It also shows me error. But it doesnt matter becasue its only to sort at the beginning. When i // this funcion and start page after save behave like doesnt exist. Whats more there is no mistakes.

//$w.onReady( () => {
// $w(“#dataset1”).onReady( () => {
// .then( () => { //. parsing error unexpected token
// sortuj();
// } )
// } );
//});

for everybody who struggle with refresh problem i did async funcion on click and it works finally

export async function button72_click(event) {
let $item = $w.at(event.context);
let newValue = $item(‘#input5’).value;
$item(‘#dataset1’).setFieldValue(‘gosc’, newValue);
await $item(‘#dataset1’).save();
await $w(“#dataset1”).refresh();
}

@sapirh When I use this the repeater does refresh, but only back to last input from “button 71”…so if user has just input an item, that item is not included in the refresh

@jeff-haskins i have chenged everything at async/await and is much easier to control and works much better

@ceglarnia lost me here at the set Field Value (‘gosc’ ??: value; $item(’ #dataset1 ').setFieldValue(‘gosc’, newValue)

Thank you so much…had the same issue and its now fixed!

what does #input5 represent? Also I assume it is input form field but after pressing submit the page where the repeater is is doing nothing no repeater refresh