Basics of list formatting in SharePoint

Introduction

In our previous article, we explored the basics of list formatting in SharePoint, learning how to apply simple styles like alternating row colors and basic conditional formatting to enhance the readability of SharePoint lists. But what if you need even more control over how your list data is presented? That’s where JSON-based conditional formatting comes into play.

In this article, we dive deeper into the world of advanced list customization. We'll explore how to use JSON to apply more complex and dynamic formatting rules based on specific conditions, such as alternating colors for rows or highlighting important data based on custom criteria. Using JSON for formatting in SharePoint offers unparalleled flexibility, allowing you to completely transform the look and feel of your lists.

By applying JSON formatting, you can create a more engaging and user-friendly experience, helping your team quickly identify important tasks, overdue items, or other key data points. In the following steps, we will show you how to easily apply this advanced formatting to your SharePoint list views, giving you full control over how data is visually displayed.

Now, let’s walk through the steps to apply the conditional formatting using JSON to your SharePoint list view. This will allow you to highlight specific rows or data points based on custom conditions, such as even or odd row indices, and apply unique styling accordingly.

Step 1. Log in to SharePoint

Sign in

  1. Open your browser and go to your SharePoint site.
  2. Enter your login credentials (email and password) to access the site.

Step 2. Open the List You Want to Format.

Settings

  1. Once logged in, navigate to your SharePoint site homepage.
  2. In the Site Contents or the Quick Launch menu (depending on your site's layout), find the list you want to format.
  3. Click on the list name to open it.

Step 3. Select the View to Format.

  1. Once the list is open, locate the View options at the top of the page. By default, it might show All Items or another view you have set up.
  2. Click on the View drop-down menu to select the view you want to format.
  3. If you haven't created any custom views yet, you can choose the default All Items view or any other view you want to modify.

Step 4. Access the Format View Option.

Format View Option

  1. With your desired view selected, look for the Format View option.
  2. This is usually found in the Settings (gear icon) or in the Column Settings (three-dot menu) on the list toolbar, depending on the SharePoint version.
  3. Click on the Format View option.

Step 5. Apply the JSON Conditional Formatting.

JSON Conditional Formatting

Once the Format View pane opens, you will see a text box where you can enter JSON code for your custom formatting.

JSON code

Paste the following JSON code into the text box.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "additionalRowClass": {
    "operator": ":",
    "operands": [
      {
        "operator": "==",
        "operands": [
          {
            "operator": "%",
            "operands": [
              "@rowIndex",
              2
            ]
          },
          0
        ]
      },
      "sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall",
      {
        "operator": ":",
        "operands": [
          {
            "operator": "==",
            "operands": [
              {
                "operator": "%",
                "operands": [
                  "@rowIndex",
                  2
                ]
              },
              1
            ]
          },
          "sp-css-backgroundColor-noFill",
          ""
        ]
      }
    ]
  }
}

Step 6. Save the Changes.

Save the Changes

  1. After pasting the JSON code, click the Save or Apply button to apply the changes.
  2. The view will refresh, and you will see that the rows in the list are now conditionally formatted with custom colors based on whether their row index is even or odd.

Explanation of the JSON Formula

Here’s a quick explanation of what the JSON formula does.

  • The $schema is a reference to SharePoint’s row formatting schema for validation and structure.
  • The additionalRowClass property is used to apply custom CSS classes to rows based on conditions.
  • The operator: "==" checks whether the row index is either even or odd.
    • If the row index is even (i.e., @rowIndex % 2 == 0), it applies the Cornflower Blue background with a smaller font size (sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall).
    • If the row index is odd (i.e., @rowIndex % 2 == 1), it applies no background color (sp-css-backgroundColor-noFill).

By applying this JSON, you are visually differentiating even and odd rows, making it easier for users to scan the list data.

Advantages and Disadvantages of Using JSON for Conditional Formatting

Advantages

  1. Highly Customizable: JSON allows you to fully customize the appearance of your list items, beyond what’s possible with standard SharePoint formatting options.
  2. Dynamic Styling: You can apply different styles based on specific conditions, such as row index, data values, or even a combination of multiple conditions.
  3. Scalability: JSON formatting works well for large datasets, allowing you to apply styles to numerous rows efficiently.
  4. Flexibility with CSS: Since you are working with CSS classes, you can easily integrate your custom styles with your organization’s existing design guidelines.

Disadvantages

  1. Learning Curve: JSON formatting requires understanding the syntax and structure of the code. If you're not familiar with JSON, there may be a learning curve.
  2. Complexity: For more advanced formatting, the JSON can become quite complex, especially when dealing with multiple conditions and custom styles.
  3. Potential for Errors: If the JSON is not structured properly, it can result in errors or the formatting not being applied as intended. Using the schema helps mitigate this risk, but it's still something to be mindful of.
  4. Limited by SharePoint's CSS Capabilities: While JSON allows for customization, you are still bound by the capabilities of SharePoint's CSS classes. If you need more advanced graphical elements, you may be limited.

All Items

Conclusion

JSON-based conditional formatting is a powerful tool for customizing your SharePoint list views. By using custom JSON code, you can create highly personalized, condition-based styles that make your data more readable and visually engaging. Whether you're coloring rows based on even or odd indexes, highlighting specific values, or applying custom font styles, JSON formatting provides the flexibility to take SharePoint list views to the next level.

In the next article, we will explore even more advanced JSON formatting techniques and how you can leverage dynamic field values to transform your SharePoint list views. Stay tuned for more tips on customizing your SharePoint experience!

Up Next
    Ebook Download
    View all
    Learn
    View all
    GE HealthCare will never ask for payment to process documents, refer you to a third party to process