JSON column formatting to preview SharePoint Online file on mouse hover


SharePoint developers can use JSON to format columns, views and customize list form.

Let us look at an example to preview the file content using a hover card, when the user moves the mouse over the file name (or any other field of your choice).

We are going to setup a new column "preview" (single line of text) and apply JSON formatting to this column.

  1. Navigate to your list/library.
  2. Select the column in view.
  3. Click Column settings --> Format this column.
  4. SharePoint JSON column formatting
    SharePoint JSON column formatting
  5. This will open a pane in the right section of screen 'Format preview column'.
  6. Copy and paste below JSON in the text box.
  7. {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "img",
      "attributes": {
        "src": "@thumbnail.medium"
      },
      "style": {
        "display": "block",
        "margin": "0 auto",
        "max-height": "100px"
      },
      "customCardProps": {
        "openOnEvent": "hover",
        "isBeakVisible": true,
        "formatter": {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.200x400"
          },
          "style": {
            "max-height": "400px"
          }
        }
      }
    }
  8. Click Preview and make adjustments, if required.
  9. Click 'Save' once comfortable with the hover card.


This is how the output will look. When user moves mouse and hover over the 'preview' column value of the file in Document Library, the hover card will popup and shows the contents of the file. You can adjust the height/width and other style parameters for the card.
Also note that we are showing a small thumbnail preview of the file in the same 'preview' column.

SharePoint file hover preview using JSON
SharePoint file hover preview using JSON


Have Questions? Post them here!
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency