You need to sign in to do that
Don't have an account?
Andreas Rikstad 5
Problem with currency in Lightning component
Hi all. I v\have a problem with my component.
I'm using lightning datatable with enabled in line editing to edit prices for products. Datatable definition looks like this:
Te problem is when I change price from 24.00 to 24.89 JS controller sends:
Do you know why it happens?
I'm using lightning datatable with enabled in line editing to edit prices for products. Datatable definition looks like this:
<lightning:datatable keyField="Id" aura:id="table" data="{!v.discountCodeItems}" columns="{!v.columns}" hideCheckboxColumn="true" defaultSortDirection="asc" draftValues="{!v.draftValues}" oncellchange="{!c.handleCellChange}" showRowNumberColumn="false" isLoading="{!v.isLoading}" wrapTextMaxLines="10" onsave="{!c.handleSave}"/>Columns definition:
component.set("v.columns",[ {label : 'Product Name', fieldName : 'linkName', type : 'url',typeAttributes : {label : {fieldName : 'Name'}}}, {label : 'Sales Price', fieldName : 'Sales_Price__c', type : 'currency', typeAttributes: { currencyCode: 'NOK'}, editable: true}, {label : 'List Price', fieldName : 'List_Price__c',type : 'currency'}, {label : 'Discount', fieldName : 'Discount', type : 'text'} ]);I read changed value using:
var draftValues = event.getParam('draftValues');and send it from component to Apex.
Te problem is when I change price from 24.00 to 24.89 JS controller sends:
[{"Sales_Price__c":"24.89","Id":"a699E000000Mc0JQAS"}]but Apex receives
{Id=a699E000000Mc0JQAS, Sales_Price__c=2489.00}If I change price back to 24 (without decimal part), Apex receives 24.
Do you know why it happens?
Hi Andreas ,
Use Decimal instead of Currency.
Check what is written under Decimal data type in the Documentations in this link
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_basic.htm
Thanks
All Answers
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation
Hi Andreas ,
Use Decimal instead of Currency.
Check what is written under Decimal data type in the Documentations in this link
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_basic.htm
Thanks
I changed the field to Decimal and it works.Anyway I have to do small investigation why is like that because in documentation they use currency as a field type in column definition:
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation
did you get any reason?
I could not change the type. Is there any other workaround?