1

I have created a lightning:datatable to display order lines. The order lines are fetched via a REST call. I parse the JSON response and add to the datatable data attribute. Everything works fine but how the values is displayed. I guess it is the same issue as with Salesforce Standard UI, but one might thing you have some more possibilities when you are writing custom code?

TL;DR How do I remove the spacing for number columns in my lightning:datatable? enter image description here

5
  • I think this styling is related to your User's Locale. You can change type of column to 'text' then it will be displayed without spaces – ytiq Sep 19 '18 at 12:39
  • how is your column attributes set up? formatting is usually controller by the attributes in the column - not so much the cell. Using the typeAttributes object you can define the formatting for every row in that column. – Ronnie Sep 19 '18 at 12:43
  • @ytiq if I change the type to text, it means I would have to change every number in the JSON to a String. Which I would like to avoid. – user3274635 Sep 19 '18 at 12:49
  • @Ronnie there is not very much you can do with the typeAttributes to format the number. At least not according to the documentation. minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigits – user3274635 Sep 19 '18 at 12:51
  • @user3274635 - the style attribute can be used to control that - look under formatted number in the documentation i provided in my answer below. The output will be of one of the formatted types. setting the style in typeAttributes should help there. – Ronnie Sep 19 '18 at 12:53
0

how is your column attributes set up? formatting is usually controlled by the attributes in the column - not so much the cell. Using the typeAttributes object you can define the formatting for every row in that column.

Documentation: https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation

you will see here that you can define the typeAttributes to format your data here. your column declaration would look like:

{
    label: 'Amount',
    fieldName: 'amount',
    type: 'currency',
    typeAttributes: { currencyCode: 'EUR'}
}

You can refer to the types HERE

3
  • 2
    My column attribute looks like the following. { label: 'Product ID', fieldName: 'productId', type: 'number', cellAttributes: { alignment: 'left' } } As I mentioned in my previous comment, the typeAttributes that can be used according to the documentation you link is the following: minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigits None which solves my problem. – user3274635 Sep 19 '18 at 14:00
  • @user3274635 the output is one of the formatted types in the documentation link i provided above - look at formattedNumber. You might find that defining typeAttributes ( not cell Attributes ) will be able to give you more formatting matching the style and other number formats you've mentioned. I am unsure what you have tried - but thought would be an ideal suggestion – Ronnie Sep 19 '18 at 22:50
  • I don't follow. I know what typeAttributes are and what they do. But as I said in my previous comment, the documentation says that there is five type attributes supported for number. Am I missing something? – user3274635 Sep 20 '18 at 10:59
0

since you are having data in JSON format. cant you just manipulate the JSON and remove the space in the data and keep the type attribute to String. that should solve your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.