문제

I am trying to archive the following within a document library modern experience on SharePoint Online:

  • All minor version (everything .1-9) the background should have the color red or similar

  • All Major versions (1.0, 2.0, 3.0 etc.) should have the background color green or similar.

It needs to be done via JSON and via the "format this column" in SharePoint Online.

Is there a way to create an "IF-Clause" checking only the last digit? If yes, I could easily identify, due to the fact, that all major version are a "0" at the end. Maybe something like RIGHT[@currentField]? If so, how do I implement that into an IF-Clause?

Current state of my pretty poor JSON:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "attributes": {
     "class": "=if(@currentField <= '0.9','sp-field-severity--warning', '')"
   },
   "children": [
     {
       "elmType": "span",
       "style": {
         "display": "inline-block",
         "padding": "0 4px"
       },
       "attributes": {
         "iconName": "=if(@currentField <= '0.9','Error', '')"
       }
     },
     {
       "elmType": "span",
       "txtContent": "@currentField"
     }
   ]
 }
도움이 되었습니까?

해결책

We can use the JSON formatting below to achieve it.

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "style": {
    "background-color": "=if(indexOf(@currentField, '.0')!=-1, 'green', 'red')",
    "color":"white" 
   },
   "children": [
     {
       "elmType": "span",
       "style": {
            "margin-top":"11px"
       },
       "txtContent": "@currentField"
     }
   ]
 }

enter image description here

다른 팁

slightly updated version making use of the supported CSS styles:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if(indexOf(@currentField, '.0')!=-1,'sp-field-severity--good', 'sp-field-severity--warning')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "=if(indexOf(@currentField, '.0')!=-1, '@currentField', @currentField + ' - Publish me!')"
    }
  ]
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top