In this SharePoint customization tutorial, we will discuss how to create a birthday view using SharePoint Online modern list view customization using JSON.
As we know in the year 2016, SharePoint online team released Modern List and Library experience in both SharePoint On-Premise and SharePoint Online. So now a day business recommends this feature for more benefits.
I am not using ant JSLink to customize our modern list rather than, I am going forward to use JSON for an excellent user interface.
If we go in detail, there are many good features added in both modern lists and libraries but here I am using those called List View Customization.
Create a birthday view using SharePoint Online modern list view customization
Step 1: I have created a SharePoint List called Birthday List and it contains the following column name.
- Title – Single Line Text
- Company – Single Line Text
- E-Mail – Single Line Text
- Department – Single Line Text
- Designation – Single Line Text
- Photo – photo
- Birthday – Date
- DOM – Single Line Text
Step 2: Next click on All Items and click on Format View to implement our customization code.
Step 3: Next copy the below code and paste it inside code editor and click on Save.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"hideSelection": true,
"hideListHeader": true,
"rowFormatter": {
"elmType": "div",
"style": {
"display": "flex",
"flex-wrap": "wrap",
"align-items": "stretch",
"padding": "8px",
"margin-bottom": "25px",
"max-width": "420px",
"border-radius": "8px",
"box-shadow": "4px 4px 8px lightblue"
},
"attributes": {
"class": "ms-bgColor-themePrimary ms-fontColor-white"
},
"children": [
{
"elmType": "div",
"style": {
"flex-grow": "1",
"display": "flex",
"flex-wrap": "wrap",
"align-items": "stretch",
"max-width": "310px"
},
"children": [
{
"elmType": "div",
"style": {
"flex": "none"
},
"children": [
{
"elmType": "div",
"style": {
"height": "100px",
"overflow": "hidden",
"border-radius": "5%",
"margin-right": "8px"
},
"children": [
{
"elmType": "span",
"txtContent": "[$Title]",
"style": {
"display": "block"
},
"attributes": {
"class": "ms-fontSize-l ms-fontWeight-semibold ms-fontColor-white"
}
},
{
"elmType": "span",
"txtContent": "[$Company]",
"style": {
"display": "=if([$Company] == '', 'none', 'block')"
},
"attributes": {
"class": "ms-fontSize-m ms-fontWeight-regular ms-fontColor-white"
}
},
{
"elmType": "span",
"txtContent": "[$Department]",
"style": {
"display": "=if([$Department] == '', 'none', 'block')"
},
"attributes": {
"class": "ms-fontSize-m ms-fontWeight-regular ms-fontColor-white"
}
},
{
"elmType": "span",
"txtContent": "[$Designation]",
"style": {
"display": "=if([$Designation] == '', 'none', 'block')"
},
"attributes": {
"class": "ms-fontSize-m ms-fontWeight-regular ms-fontColor-white"
}
}
]
}
]
}
]
},
{
"elmType": "div",
"style": {
"display": "flex",
"flex-direction": "column",
"max-width": "310px",
"min-width": "95px"
},
"children": [
{
"elmType": "div",
"style": {
"flex-grow": "1"
},
"children": [
{
"elmType": "span",
"style": {
"display": "=if([$Birthday] <= @now,'block','none')"
},
"attributes": {
"iconName": "BirthdayCake"
}
},
{
"elmType": "span",
"style": {
"display": "block"
},
"attributes": {
"class": "ms-fontWeight-semibold ms-fontSize-m"
},
"txtContent": "=if([$Birthday] <= @now,'Happy Birthday!', 'Next Birthday')"
},
{
"elmType": "span",
"style": {
"display": "=if([$Birthday] == '', 'none', 'block')",
"padding-left": "0px",
"font-size": "14px"
},
"txtContent": "[$DOM]",
"attributes": {
"class": "ms-fontSize-s ms-fontWeight-regular ms-fontColor-white"
}
},
{
"elmType": "span",
"style": {
"display": "=if([$Birthday] == '', 'block', 'none')",
"padding-left": "8px"
},
"txtContent": "No Birthday Entered",
"attributes": {
"class": "ms-fontSize-s ms-fontWeight-semilight ms-fontColor-white"
}
}
]
},
{
"elmType": "div",
"style": {
"flex": "none",
"display": "flex",
"flex-direction": "row-reverse",
"flex-wrap": "nowrap"
},
"children": [
{
"elmType": "a",
"style": {
"display": "=if([$EMail] == '', 'none', 'block')"
},
"attributes": {
"class": "ms-fontSize-xs ms-fontWeight-regular ms-fontColor-white ms-fontColor-white--hover",
"href": "='mailto:' + [$EMail] + '?subject=Happy Birthday!\r\n'"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "Mail"
}
}
]
}
]
}
]
}
]
}
}
Step 4: Once I click on Save button, the SharePoint List view got changed to different view which same as below screenshot
This is all about customization of List View in SharePoint Online Modern List.
You may like following tutorials:
- SharePoint Online modern list view customization using JSON
- SharePoint Online mega menu and Site Customizations
- How to add links to top link bar in SharePoint
- SharePoint Online modern list column formatting using JSON
Reference: for theme color change and generate the JSON format , you can follow the below URL
- https://sharepoint-json-formatter.herokuapp.com/
- https://docs.microsoft.com/en-us/sharepoint/dev/design/themes-colors
- https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting
- https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/view-formatting
- How to change Listview color using SharePoint Online modern list view customization
- SharePoint modern list view customization example
In this tutorial, we learned how to Create a birthday view using SharePoint Online modern list view customization using JSON.
Rajkiran is currently working as a SharePoint Consultant in India . Rajkiran having 7+ years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).