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
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!
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.
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.
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://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
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