function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Balu Phrabha123Balu Phrabha123 

Add Dollar $ to the data table list.

HI All,

For the data table i need to show the "$" in front of Revenue. 

Example: $98574.87M

{ label: 'Revenue', sortDirection: 'desc' ,sortable: true, initialWidth:120, fieldName: 'prospectRevenue', type: 'text'},
{ label: 'Industry', sortable: false, fieldName: 'naics6Description', type: 'text'},
{ label: 'City', sortable: true, fieldName: 'city', initialWidth:120, type: 'text'},
{ label: 'Zip', sortable: true, fieldName: 'postalCode', initialWidth:80, type: 'text'},
{ label: 'HQ', sortable: true, fieldName: 'headquarter', initialWidth:80, type: 'text'}

User-added image

for showing revenue logic. Please see below code for reference.
.JS
// Revenue logic
jsresult.prospectSummary.forEach(function(record){
if(record.prospectRevenue){
record.prospectRevenue = Math.round(Math.abs(Number(record.prospectRevenue)) / 1.0e+6 *100)/100 + "M";
console.log('Revenue in Millions', record.prospectRevenue);
}

Regards,
Balu
JonRodriguesJonRodrigues
Hi Balu, In the column declaration, the type must be currency
{label: 'Revenue', sort Direction: 'desc', sortable: true, initial Width: 120, fieldName: 'prospect Revenue', type: 'currency'}
This way the currency configured in the org will define the dollar sign in the field.

Let me know, if I managed to help you that way?

Regards, 
Jonathan
David Zhu 🔥David Zhu 🔥
@Balu,
1. As Jon mentioned, type currency should work (I have a similar component and it is working), if you just want to dispaly something linke '$1,000,000.00'. If you cannot see the data, please make sure the Revenue is defined a decimal type in your apex controller.
2. JS might not work as you are trying to modify on data through wired service.
3. If you want to see something like '$3.5M', then you have to create a string field (let's call it RevenueString) and format it before it is called by LWC wired service.
David Zhu 🔥David Zhu 🔥
Hi @Balu, I found a way to handle your case without change the apex code.
1. Assume the lightning-datatable is binding to property @track data
2. Keep reveneu column type as 'text'
3. in your wired service method
wiredYourMethod(result) {

  if (result.data) {

            var temp = []; 
            for(var key in result.data){
                var record = result.data[key];
                var updatedRecord = {};
                updatedRecord.xxxxx= record.xxxxx;   // assign value from all fields of record to updated Record. make sure they match the column field name.
                updatedRecord.yyyyy= record.yyyyy;
                updatedRecord.revenue = '$' + Math.round(Math.abs(Number(record.revenue) / 1.0e+6 *100)/100) + 'M';
                temp.push(updatedRecord);
              }
            this.data = temp;   //assign record with revenue format you expect to property this.data
            this.error = undefined;

        } else if
       {...............}