Adding Commas To Number Code Not Working Under Pagination

I have a repeater connected to a dataset and it has a text that shows a number, and i added the code to add commas to these numbers and the code works perfectly fine on the first page, however when i click on the second or any other page rather than the first page the code stops working and the numbers stop displaying commas in them

this is the code i’m having an issue with:

$w.onReady( function () {
$w(“#dataset1”).onReady( () => {

$w(‘#repeater1’).forEachItem( ($w, itemData, index) => {
const numberWithCommas = (x) => {
return x.toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
}
$w(‘#text59’).text = numberWithCommas(parseInt($w(‘#text59’).text));
} );
});

can someone please tell me what code should i use to make this code work on all pages?
and if there is an error in the code please notify me

For this purpose, onItemReady would be preferable since it runs when each repeated item is created. This code above is running only on the repeated items that show on the first page.

Also, change it to this to avoid any possible conflicts between different declarations of $w. Try to give all of your variables their own unique name:

$w.onReady(function () {
$w("#dataset1").onReady( () => {

$w('#repeater1').forEachItem( ($item, itemData, index) => {
const numberWithCommas = (x) => {
return x.toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
$item('#text59').text = numberWithCommas(parseInt($item('#text59').text));
} );
});

Thanks Alot David, Appreciate It!

Hi Anthony

I’ve tried adding this code to onItemReady handler but somehow the numbers start showing only one part … for example

Number in the database: 150,000

Number that gets displayed: 150

Do you know what the reason could be?