In SharePoint Online List, how to use JSON to wrap text and to give alternate background colors to list items in the view?

frob 4,281 Reputation points
2022-02-04T19:58:19.457+00:00

Hi there

In SharePoint Online List, how to use JSON to wrap text and to give alternate background colors to list items in the view?
How to modify the code below to add the alternating background for list items to it?

Thanks.

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style":{
        "white-space":"wrap"
  }, 
  "txtContent": "@currentField"
}
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,466 Reputation points
    2022-02-07T05:51:14.73+00:00

    Hi @frob ,

    You could use following JSON code to alternate the background color.

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",  
      "additionalRowClass": "=if(@rowIndex%2==0,'ms-bgColor-themeLight','')"  
    }  
    

    Your JSON code is SharePoint column formatting, it only works in column. You have to format the columns you want to wrap text with this codes.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.