0

I want to display probability field in lightning datatable which is already calculated as percentage. But two extra zeros are getting added at end of every value. data type for column is percent. How can I stop this calculation and display values as is. ex probability 70 displaying 7000

1
  • 5
    Please share the code, guessing in the dark without it.
    – Girbot
    Commented Jan 25, 2022 at 12:49

2 Answers 2

0

Try using lightning formatted number and use the percentage like

<lightning-formatted-number value={value} format-style="percent"></lightning-formatted-number>
4
  • 1
    How to use formatter in datatable? Commented Jan 27, 2022 at 5:58
  • here is one example from a working solution of mine: <td> <div class="slds-truncate" if:true={clientData.totalsForAccount.annuityLoan} title={clientData.totalsForAccount.annuityLoan}> <lightning-formatted-number value={clientData.totalsForAccount.annuityLoan} format-style="decimal" maximum-fraction-digits="1" minimum-fraction-digits="1"></lightning-formatted-number> </div> <div class="slds-truncate centered-text" if:false={clientData.totalsForAccount.annuityLoan}>-</div> </td> Commented Jan 27, 2022 at 7:59
  • 1
    How to use in this<template> <lightning-datatable data="{data}" columns="{columns}" key-field="id" onrowselection="{getSelectedName}" > </lightning-datatable> </template> Commented Jan 27, 2022 at 8:28
  • not really possible. you should transform your datatable in a slds table and everything should work just fine Commented Jan 27, 2022 at 13:09
0

Solution I have done: import percentfixed from './percentfixed.html';

export default class MyDatatable extends LightningDatatable {
    static customTypes = {
        percentfixed : {
            template : percentfixed,
        } 
    }
}

Then: percentFixed.html:

<template>
    <lightning-formatted-number value={value} format-style="percent-fixed" maximum-fraction-digits="2"></lightning-formatted-number>
</template>

then you can use you new datatable component with new type percentFixed on column.

1
  • How do I use this on my datatable. js and html?
    – user2018
    Commented Dec 2, 2022 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .