Code stops working when load more button is clicked

Hey there. I have this code I use to display numbers with comma separators and $ symbol. One code is for a table and another code is for a repeater. Both the repeater and the table have a Load More button however when I click it to load more info the code doesent work anymore so the info is displayed without the comma separators etc. Any help? Sorry if my code is a mess…not a pro

CODE FOR TABLE:

$w.onReady( function () {
$w( “#dataset2” ).onReady(() => {
let rows = $w( “#table1” ).rows;
let count = $w( “#table1” ).rows.length;
for ( let i = 0 ; i < count; i++) {
let oldScore = rows[i][ “price” ]
console.log( "old score is " + oldScore);
var number = Number(oldScore)
console.log( "revised score is " + number.toLocaleString());
let revisedScore = number.toLocaleString();
rows[i][ “price” ] = ‘$’ +revisedScore;
}
$w( ‘#table1’ ).rows = rows
})

$w( “#dataset2” ).onReady(() => {
let rows = $w( “#table1” ).rows;
let count = $w( “#table1” ).rows.length;
for ( let i = 0 ; i < count; i++) {
let viejoScore = rows[i][ “precioArriendo” ]
console.log( "viejo score is " + viejoScore);
var number = Number(viejoScore)
console.log( "revised score is " + number.toLocaleString());
let revisadoScore = number.toLocaleString();
rows[i][ “precioArriendo” ] = ‘$’ +revisadoScore;
}
$w( ‘#table1’ ).rows = rows
})

})

CODE FOR REPEATER:

$w.onReady(() => {
$w( ‘#dataset1’ ).onReady(() => {
$w( ‘#propertiesRepeater’ ).forEachItem( ($w, itemData, index) => {
const numberWithCommas = (x) => {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “.” );
}
$w( ‘#text58’ ).text = numberWithCommas(parseInt($w( ‘#text58’ ).text));
$w( ‘#price’ ).text = numberWithCommas(parseInt($w( ‘#price’ ).text));
} );
});

  $w( "#propertiesRepeater" ).onItemReady( () => { 

$w( “#propertiesRepeater” ).forEachItem( ($item, itemData, index) => {
if ( $item( ‘#statusText’ ).text === “Arriendo” ) {
$item( ‘#text57’ ).show();
$item( ‘#text58’ ).show();
$item( ‘#text59’ ).show();
$item( ‘#text60’ ).hide();
$item( ‘#text46’ ).hide();
$item( ‘#price’ ).hide();
}
}
);
});

$w( “#dataset1” ).onReady( () => {
$w( “#propertiesRepeater” ).onItemReady( () => {
$w( “#propertiesRepeater” ).forEachItem( ($item, itemData, index) => {
if ( $item( ‘#statusText’ ).text === “Venta” ) {
$item( ‘#text57’ ).hide();
$item( ‘#text58’ ).hide();
$item( ‘#text59’ ).hide();
$item( ‘#text60’ ).show();
$item( ‘#text46’ ).show();
$item( ‘#price’ ).show();
}
}
);
});
});
});

First of all, in JavaScript there are built-in methods to format a number with as currency and you don’t have to add the comma and the currency symbol spereatly.
See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleStrin

and
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

Second, instead of forEachItem, try .onItemReady

@J.D. the .onItemReady worked perfectly for the repeater, thank you! My question now is how to adapt the currency code to work on the table I have connected to my dataset. I find this useful:

const number = 123456.789;
console.log(new Intl.NumberFormat(‘de-DE’, { style: ‘currency’, currency: ‘USD’ }).format(number));

How do I apply it to the table?

Anyone available?

A table works almost the same way as a repeater.
Connect your table to your dataset.

Remember that the repeater has a repeated container that holds all the elements for that one container, hence why you need to code differently with repeaters, so you can manually add a button to the container to show this.
https://www.wix.com/corvid/reference/$w.Repeater.html

However with a table, the column data is all either taken from your connected dataset or the code that you have added to your page for it.
https://www.wix.com/corvid/reference/$w.Table.html
https://www.wix.com/corvid/reference/$w.Table.html#Column

So you can’t have a button inside a table to have something hide or show, that is what the repeaters are for.

The only thing that you can try here is to look at using onRowSelect or onCellSelect to have something happen.
https://www.wix.com/corvid/reference/$w.Table.html#onRowSelect
https://www.wix.com/corvid/reference/$w.Table.html#rows
https://www.wix.com/corvid/reference/$w.Table.html#onCellSelect
https://www.wix.com/corvid/reference/$w.Table.html#onDataChange

Thank you @GOS and @russian-dima. I think I havent explained myself well. I just need my table, which is already connected to my dataset, to display two columns of numbers with comma separators and the $ symbol as these numbers represent currency.
@GOS send me this code through a link:
const number = 123456.789;
console.log(new Intl.NumberFormat(‘de-DE’, { style: ‘currency’, currency: ‘USD’ }).format(number));

and I was just wondering how to apply it for those table columns to display my numbers as currency :grinning: