Back to column formats
Column formattingSharePoint Online

Expand Collapse Format

Demonstrates creating a button to register for a course.

Expand Collapse Format formatting preview
Sample preview · View original animation

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "style": {
        "height": "50px"
      },
      "children": [
        {
          "elmType": "div",
          "children": [
            {
              "elmType": "div",
              "txtContent": "Click to expand"
            },
            {
              "elmType": "div",
              "style": {
                "display": "=if([$Expand]==false,'none','inline-block')"
              },
              "txtContent": "@currentField"
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "height": "50px",
        "padding-left": "10px"
      },
      "children": [
        {
          "elmType": "div",
          "style": {
            "cursor": "pointer"
          },
          "attributes": {
            "iconName": "=if([$Expand]==true, 'CaretUpSolid8','CaretDownSolid8')",
            "class": "ms-fontSize-18 ms-fontColor-black ms-fontWeight-bold"
          },
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "Expand": "=if([$Expand]==true, 0,1)"
            }
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

The following sample provide a format that display content based on expand/collapse effect using support column and option setValue.

screenshot of the sample

Note - This relies on updating the underlying list item meaning that the expanded/collapse state applies to ALL users viewing the item

View requirements

  • This format can be applied to any column type though the example is based on a single line of text field.
Column Name Type
Content single line of text
Expand Yes/No - default value "No"

Sample

Solution Author(s)
text-expand-collapse-format.json André Lage

Version history

Version Date Comments
1.0 January 10, 2022 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes