Dynamic currency in Lightning Datatable

Hello! In salesforce we often meet situation when we need to display set of data including currency. The best way to achieve this is using Lightning Datatable, which supports currency type. But we can have a problems when it comes to multicurrency data. In such case it is possible to have different currency in each row of table. Because of it we need to find a way to provide correct currency for each of them. Fortunately for us it is pretty simple to use dynamic currency in Lightning Datatable .

To do that, we just need to define additional property in datatable definition. But firstly we need to grab data about currency from salesforce, and keep them as additional field in data structure in our case it will be “currencyIsoCode” field. Secondly we can add “currencyCode“, to datatable definition. After that currency field definition in datatable will look like below:

@track columns = [
        { label: 'House Name', fieldName: 'HouseName', type: 'text' },
        { label: 'House Code', fieldName: 'HouseCode', type: 'text' },
        { label: 'House Price', fieldName: 'HousePrice', type: 'currency', typeAttributes: { currencyCode: { fieldName: 'CurrencyIsoCode' }, currencyDisplayAs: "code" }}

In 4 line we use “currencyCode” attribute and pass there value of “CurrencyIsoCode” field from our data.

<lightning-datatable key-field="id" data={data} columns={columns} onrowselection={handleSelect} selected-rows={selectedRows}></lightning-datatable>

And that’s simple way to use dynamic currency in Lightning Datatable. In the other hand you can take a look how to create simple validation for you data in recordEditForm here or how to refresh data on record page by clicking here.



5 1 vote
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
1 year ago

Hi, your code is failing, here is working code:

{ label: 'Amount', fieldName: 'Amount', type: 'currency', typeAttributes: { currencyCode: { fieldName: 'CurrencyIsoCode' }, currencyDisplayAs: 'code' }}

there are missing brackets 🙂

Close Menu
Would love your thoughts, please comment.x