Display Calendar using FullCalendar and Rest API in SharePoint

Display the Calendar Using Jquery Full Calendar and SharePoint Rest API
SharePoint deveopment training course

In this SharePoint 2013 tutorial, I will show you how to create your own jQuery Calendar view using the simple jQuery and SharePoint Rest API.

Display Calendar using FullCalendar and Rest API in SharePoint

We will use here FullCalendar library which is also available in on NPM or Yarn.

We can install using the npm command like below:

npm install --save @fullcalendar/core @fullcalendar/daygrid

I have used the fullcalendar plugin as it is very easy to use. It is highly customizable and very lightweight.

I have created a Calendar list on my site and named it as ‘UpcomingEvents’. We will use this list to store our events or meetings.

You will be required to add the reference to the following files from FullCalendar.io.

<link href="../SiteAssets/css/fullcalendar.css" rel="stylesheet"/>
<link href="../SiteAssets/css/fullcalendar.print.css" rel="stylesheet" media='print' />
<script type="text/javascript" src="../SiteAssets/js/jquery-1.11.0.min.js" ></script>
<script type="text/javascript" src="../SiteAssets/js/fullcalendar.min.js" ></script>
<script type="text/javascript" src="../SiteAssets/JqueryFullCalendar.js" ></script>

Create JqueryFullCalendar.txt and add the above-mentioned references in the file,

JqueryFullCalendar.txt

<link href="../SiteAssets/css/fullcalendar.css" rel="stylesheet"/>
<link href="../SiteAssets/css/fullcalendar.print.css" rel="stylesheet" media='print' />
<script type="text/javascript" src="../SiteAssets/js/jquery-1.11.0.min.js" ></script>
<script type="text/javascript" src="../SiteAssets/js/moment.min.js" ></script>
<script type="text/javascript" src="../SiteAssets/js/fullcalendar.min.js" ></script>
<script type="text/javascript" src="../SiteAssets/JqueryFullCalendar.js" ></script>
<div id='calendar' class="float:left search-results"></div>

JqueryFullCalendar.js will have our custom code to load the events from the SharePoint List and render it in the Jquery Full Calendar. This calendar will support recurring events as well.

JqueryFullCalendar.js

var ele = [];
var listUrl = "../_vti_bin/listdata.svc/";
$(document).ready(function() {
Retreive();
});
function Retreive() {
var listUrl = "../_vti_bin/ListData.svc/UpcomingEvents";
$.ajax({
url: listUrl,
type: "GET",
data: {
$select: "Title,Description,StartTime,EndTime,AllDayEvent,Recurrence,Id"
},
headers: {
accept: "application/json;odata=verbose"
},
success: function(data) {
$.each(data.d.results, function(i) {
currObj = this;
var fADE = currObj.AllDayEvent;
if (fADE != null) {
if (fADE == 0) {
thisADE = false
} else thisADE = true;
}
var thisID = currObj.Id;
var thisTitle = currObj.Title;
var thisRecurrence = currObj.Recurrence;
var thisDesc = currObj.Description;
var x = new Date(parseInt(currObj.StartTime.substr(6)));
var y = new Date(parseInt(currObj.EndTime.substr(6)));
ele.push({
title: currObj.Title,
id: currObj.Id,
start: x,
description: currObj.Description,
end: y,
allDay: thisADE,
});
});
BindCalendar();
}
});
}

function BindCalendar() {
var calendarioDiv = $('#calendar');
var fullCalendar = calendarioDiv.fullCalendar({
events: ele,
error: function() {
alert('Error');
},
editable: false,
firstDay: 0,
monthNames: ['JANUARY', 'FEBRUARY','MARCH', 'APRIL', 'MAY','JUNE', 'JULY', 'AUGUST', 'SEPTEMBER','OCTOBER', 'NOVEMBER', 'DECEMBER'
],
dayNames: ['Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday'
],
dayNamesShort: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
allDay: true
});
}

Add the Content Editor web part on your page and add the reference to the JqueryFullCalendar.txt file in it. Below is the output

how to use FullCalendar library in SharePoint

You may like following SharePoint Rest API tutorials:

This is how we can use fullcalendar library to display calendar view using Rest API and jQuery in SharePoint Online and SharePoint 2013/2016.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope