How to Display Numbers with a Comma Separator

Hey Guys,

Struggling with understanding how to get my code to display commas. While I know its been attempted to be answered before my situation is a bit unique I think.

In my my database I have both text and numbers (different columns). The numbers are inputted as 0000.00, but displayed with a comma within the database. When I tried to use this code:

$w.onReady( function () {

$w(“#dataset1”).onReady(() => {
var number = Number($w(“#table1”).text);
$w(“#totalDealValue”).text = number.toLocaleString();

});

});

It stated “text does not exist for table1” and “totalDealValue is not a valid selector”

I’m not sure how to select a particular column within the dataset to display the information within the column with a comma.

any help would be appreciated. Still learning to code!

Best,
Gabe

How can this line here be a number when you have it as text, might need to try value instead.

 var number = Number($w("#table1").text); 

https://www.wix.com/corvid/forum/community-discussion/adding-comma-to-price
https://www.wix.com/corvid/forum/community-discussion/adding-commas-to-numbers-pulled-from-collection

https://www.wix.com/corvid/forum/community-discussion/can-t-display-number-in-a-textbox
https://www.wix.com/corvid/forum/community-discussion/search-database-number-value
https://www.wix.com/corvid/forum/community-discussion/totaling-values-to-display-a-number
https://www.wix.com/corvid/forum/community-discussion/insert-function-number-as-text-can-you-help
https://www.wix.com/corvid/forum/community-discussion/user-number-input-calc-then-output-solved

Thanks for the help @givemeawhisky however, I changed it as you said to value and it says "value does not exist for “table1” and totalDeal Value is not a valid selectior.

This is what I updated it to:
$w.onReady( function () {

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

var number = Number($w(“#table1”).value);
$w(“#totalDealValue”).value = number.toLocaleString();

}); 

});

Thanks for the links as well, I have gone through them prior and still don’t quite understand what im missing here.

 $w("#totalDealValue").value = number.toLocaleString(); 

Change this one back to text.

Also, just thinking, is your #table1 a table that you have added through the Wix Editor menu?

Please give us more info, as if it is then you can’t just use #table1 which is the name of the table and expect to get any values from it. You will need to add code to select a row or column and have something happen…
https://www.wix.com/corvid/reference/$w.TableCellEvent.html
https://www.wix.com/corvid/reference/$w.TableRowEvent.html
https://www.wix.com/corvid/reference/$w.Table.html

Yes, #table1 one is added via the Wix Editor. Thank you again for the links, I think perhaps the appropriate code would be ColumnIndex. I’ve added it as such. Ive included the complete code below:

import wixData from “wix-data”;

let debounceTimer;
export function iAdviser_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iAdviser’).value);
}, 500);
}

let lastFilterTitle;
function filter(title) {
if (lastFilterTitle !== title) {
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘adviser’,title));
lastFilterTitle = title;
}
}

$w.onReady( function () {
$w(“#dataset1”).onReady(() => {
let cellColumnIndex = event.cellColumnIndex;
var number = Number($w(“#table1”)text);
$w(“#totalDealValue”).value = number.toLocaleString();

}); 

});

The last part is what is relevant to my question regarding outputting the numbers with a comma.

Hey man, I kinda did a work around and just set the field as text rather than number. Thanks for the help and links, much appreciated!