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.
- Navigate to your list/library.
- Select the column in view.
- Click Column settings --> Format this column.
- This will open a pane in the right section of screen 'Format preview column'.
- Copy and paste below JSON in the text box.
- Click Preview and make adjustments, if required.
- Click 'Save' once comfortable with the hover card.
{
"$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"
}
}
}
}
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.
Have Questions? Post them here!
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!