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
2 Answers
Try using lightning formatted number and use the percentage like
<lightning-formatted-number value={value} format-style="percent"></lightning-formatted-number>
-
1
-
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 -
1How 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
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.