2

I successfully added conditional coloring of cells in a column of a custom list using JSON.

So I have browsed several resources at M$ for formatting options. E.g. column-formatting

I wasn't able to find any possibility to display numbers right flushed. Additionaly I want to display only the integer part of a float. How can I do that?

Bonus: How can I display a number in exponential form e.g. \$2.345\cdot10^{12}\$ (it's a pity tex formatting doesn't work here)

Update Here's my current json code:

{
 "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
 "elmType": "div",
 "attributes": {
    "class": "=if(@currentField < 10000, 'sp-field-severity--good', if(@currentField < 300000, 'sp-field-severity--low', if(@currentField < 2000000, 'sp-field-severity--warning', if(@currentField < 20000000, 'sp-field-severity--severeWarning', 'sp-field-severity--blocked'))))+ ' ms-fontColor-neutralSecondary'"
  },
 "children": [
    {
     "elmType": "span",
     "style": {
        "display": "inline-block",
        "padding": "0 4px"
       },
     "attributes": {
        "iconName": "=if(@currentField <= 70,'Error', '')"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

The first elmType isn't relevant, it's a relic from the sample code where I started :)

2
  • 1
    For both, you basically need to add css styles to your json formatter. If you can post your current JSON, we can assist with how to add the styles you need.
    – willman
    Commented Mar 11, 2020 at 18:52
  • @willman: I added my code to the question.
    – Ariser
    Commented Mar 11, 2020 at 21:57

1 Answer 1

1

To align your cell to the right you can modify the last bit of your JSON:

{
 "elmType": "span",
   "style": {
     "width": "100%",
     "text-align": "right"
   },
  "txtContent": "@currentField"
}

To get just the integer bit you could do the following: Adjust for correct decimal sign...

"txtContent": "=if(indexOf(toString(@currentField),'.')>=0,substring(toString(@currentField),0,indexOf(toString(@currentField),'.')),@currentField)"

You also have the ceiling or floor functions, unfortunately there doesn't seem to be a roundor intfunction.

The bonus-bit I will have to leave for someone else!

1
  • 1
    This looks very good. And as the column is already a calculated column, I realised I can do the rounding in the column calculation field using the "ROUND(epression,0)" function.
    – Ariser
    Commented Mar 12, 2020 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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