Back to column formats
Column formattingSharePoint Online

Liked By Users

This sample demonstrates showing the users who have liked an item.

Liked By Users formatting preview
Sample preview · View original image

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",
  "style": {
    "margin": "3px"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "padding": "5px 10px 5px 10px",
        "cursor": "pointer",
        "white-space": "nowrap",
        "border-radius": "5px",
        "display": "flex",
        "align-items": "center"
      },
      "attributes": {
        "class": "ms-bgColor-themePrimary ms-bgColor-themeTertiary--hover ms-fontColor-white"
      },
      "children": [
        {
          "elmType": "span",
          "style": {
            "font-size": "15px",
            "margin-right": "5px"
          },
          "attributes": {
            "iconName": "Contact"
          }
        },
        {
          "elmType": "span",
          "txtContent": "LikedBy"
        }
      ],
      "customCardProps": {
        "openOnEvent": "hover",
        "directionalHint": "rightCenter",
        "isBeakVisible": true,
        "formatter": {
          "elmType": "div",
          "style": {
            "max-height": "300px",
            "padding": "5px 20px 5px 20px",
            "display": "flex",
            "flex-direction": "column"
          },
          "children": [
            {
              "elmType": "div",
              "txtContent": "= if([$LikesCount] == '' , '0' , [$LikesCount]) + ' Likes'",
              "style": {
                "padding": "10px",
                "font-weight": "bold",
                "font-size": "15px"
              }
            },
            {
              "elmType": "div",
              "children": [
                {
                  "forEach": "personIterator in [$LikedBy]",
                  "elmType": "div",
                  "style": {
                    "margin-bottom": "5px",
                    "display": "flex",
                    "align-items": "center"
                  },
                  "children": [
                    {
                      "elmType": "img",
                      "style": {
                        "width": "32px",
                        "height": "32px",
                        "border-radius": "50%",
                        "margin-right": "5px"
                      },
                      "attributes": {
                        "src": "=getUserImage([$personIterator.email], 'S')",
                        "title": "[$personIterator.title]"
                      }
                    },
                    {
                      "elmType": "span",
                      "txtContent": "[$personIterator.title]"
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates showing the users who have liked an item.

screenshot of the sample

Prerequisites

Enabling the ratings feature

The ratings feature is available by default in the team site, but not in the communication site. If you want to use the ratings feature in the list of communication sites, you need to enable the feature GUID 915c240e-a6cc-49b8-8b2c-0bff8b553ed3. The following is an example of how to enable it using PnP PowerShell.

$targetURL = "https://<tenent name>.sharepoint.com/sites/<site name>"
Connect-PnPOnline -Url $targetURL -Interactive
Enable-PnPFeature –identity 915c240e-a6cc-49b8-8b2c-0bff8b553ed3 -Scope site
Disconnect-PnPOnline

Add a ratings feature to the list

  1. Click gear icon

  2. Click List Settings

  3. Under General Settings, click Rating settings.

    screenshot of how to add the ratings feature

  4. Under Allow items in this list to be rated?, click Yes.

  5. Under Which voting/rating experience would you like to enable for this list?, click Likes.

  6. Click OK.

    screenshot of how to add the ratings feature

View requirements

  • Add a ratings feature to the list and display a like button.
  • In addition, one field needs to be defined
Type Internal Name Required
Single line of text LikedBy No

Sample

Solution Author(s)
generic-likedby.json Tetsuya Kawahara

Version history

Version Date Comments
1.0 October 22, 2021 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