Forum Discussion

MilanNikolic's avatar
MilanNikolic
Copper Contributor
Jul 11, 2022

List view does not load json formating

Greetings,

 

I've created a list containing peoples holiday schedule. I wanted to show this in a calendar so I created a View for the list. Then base on a column of type Choise I want to colour the events in the calendar.

Here if is the list:

Here is the desired calendar view:

I formatted this with JSON as fallows:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema.json",
"additionalEventClass": {
"operator": ":",
"operands": [{
"operator": "==",
"operands": [
"[$Status]",
"Waiting Approval"
]
},
"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkRed' , 'sp-css-backgroundColor-BgCoral sp-css-color-CoralFont')+' sp-field-fontSizeSmall'",
"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGreen' , 'sp-css-backgroundColor-BgMint sp-css-color-LightMintFont')+' sp-field-fontSizeSmall'"
]
}
}
My problem is that when I first open the list in this view (as default) the formatting is not displayed. And after I switch between views the formatting starts working.

How can I fix this, is there something wrong with my JSON code?
 
Thanks in advance. 
  • JohanBokhorst's avatar
    JohanBokhorst
    Copper Contributor

    MilanNikolic I have the same here! When I go directly to the url of the desired view, then the json code doesn't work completely, it seems. If I first go to the default view and then via the menu to the desired view, everything is visible. However, when I click refresh, part of the formatting disappears again. Any ideas yet?

    • JohanBokhorst's avatar
      JohanBokhorst
      Copper Contributor

      @MilanNikolic Solved my problem: 

       

      In "Edit current view" of the relevant view, not all necessary columns were selected. I can imagine that when calling the view directly, this did not load all the underlying data.

      • ganeshsanap's avatar
        ganeshsanap
        MVP

        JohanBokhorst This is a known behavior of JSON formatting in SharePoint.

         

        If you are referencing any list column in JSON (for example: [$Status]), you have to include/show this column (Status) in list view else JSON formatting will not work as expected.

         

        Where Status is the internal name of your list column. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online? 


        Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources