Hello everyone. I have this code I found here in the forum to display numbers in two table columns as currency (with comma separators and $ symbol). Although it does its job, I found it is interfering with the rest of my page codes so filters, buttons and other things stop working well. Any ideas?
import wixData from 'wix-data'; // For full API documentation, including code examples, visit http://wix.to/94BuAAs export function button24_click(event) { $w('#dataset1').setFilter(wixData.filter() .contains("title", $w('#input30').value)); } export function button16_click(event) { $w('#dataset1').setFilter(wixData.filter()); $w('#input30').value = "" } $w.onReady(function () { $w("#dataset1").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; 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 }) })
@Yisrael (Wix) and @Ahmad Thank you for answering and for your suggestions I will explain further.
All the code I copied has been adapted to my website and needs so no problem with that. I have a real estate website and I have created a dashboard where I cann see a full list of my properties in a table. The first part of the code regards a search bar so I can find properties by title or agent name. This code works great UNLESS I add the second part of the code which adds comma separators and $ symbols so the property prices are displayed as currency. This second part works great, it displays the numbers as I want, but it prevents my search bar to display the results I search in my table. Here is a screenshot. As you see I have no errors in my console and it seems like everything is fine when I click my search button but the table isnt displaying the results as it should. Please see below for further detail.
FIRST PAR OF THE CODE (performs great until I add the second part of the code):
import wixData from 'wix-data'; // For full API documentation, including code examples, visit http://wix.to/94BuAAs export function button24_click(event) { $w('#dataset1').setFilter(wixData.filter() .contains("title", $w('#input30').value) .or(wixData.filter().contains("agentName", $w('#input30').value)) ); } export function button16_click(event) { $w('#dataset1').setFilter(wixData.filter()); $w('#input30').value = "" }
SECOND PART OF THE CODE (performs great always but it prevents the first part of the code to perform as it should):
$w.onReady(function () { $w("#dataset1").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; 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 }) })
Here is the link to this page if you want to check.
A futher issue I have is if I add a log more button for the table to load more properties it wont work neither. Why is all this happening here?
I hope this explaination is better. Thank you for your time and patience🐢
Hi 🖐
I don't think that's what causing the page stop working, sometimes you may encounter invisible errors that don't come until you log them, so I suggest using the console to log where the code reach, give feedback on completed or rejected actions, put some logs every 2-3 lines to monitor where the code stops, and then narrow code further until you identify what's causing the the code to stop, then log its error if it has any, or log the result to see what it gives you.
You will need to provide more information for anyone to be able to provide assistance.
What you you trying to do? What is working? What isn't working? What do you mean by "it is interfering with the rest of my page codes"?
Please realize that you can't just "copy and paste" code and expect it to work. You need to understand what's happening if you expect to be able to write code that does what you want.