Question

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 :)

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top