Fullcalendar - Add custom fields from JSON feed to javascript object - fullcalendar

C# .net Core MVC fullcalendar.js
I have the JSON feed working great from my controller. I want to add a couple of custom fields to the JSON feed like description and type.
I can create manual events in the View Javascript and add all kinds of extra fields just fine. I'm trying to handle the same extra fields when they come from a url JSON feed. How can I change the object in the View javascript so that data is being stored?
Sample from JSON file:
[
{
"id": 2020,
"batch": "c8762027-91d6-4892-af45-9737e86cd1a8",
"type": "Schedule",
"date": "2022-02-17",
"title": "Schedule - 2020",
"description": "test",
"notes": null,
"color": "blue"
},
{
"id": 2021,
"batch": "45fe545f-a274-4e38-af85-6340c98ee4c0",
"type": "Schedule",
"date": "2022-03-01",
"title": "Schedule - 2021",
"description": "test",
"notes": null,
"color": "blue"
}
]
The events get created on the calendar with the correct ID, title, color, etc. .. all the standard fields. The description and type do not get filled.
From the View file
<script type="text/javascript">
let calendar = initCalendar();
function initCalendar() {
var calendarEl = document.getElementById('calendar');
let calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
weekNumbers: true,
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
eventClick: function (info) {
//alert('Title: ' + info.event.title + ' - ' + 'ID: ' + info.event.id);
document.getElementById('Title').innerHTML = info.event.title;
document.getElementById('Description').innerHTML = info.event.description;
$('#EventDetail').modal('show');
},
events: {
url: '#Url.Action("Calendar")'
}
});
calendar.render();
return calendar;
}
</script>
ends up showing

I figured it out. When the calendar receives the JSON stream, it will add non-standard fields to the extendeProps section automatically. So if you are sending in your stream a "description" field (which is not a standard field), it will be added to the extendedProps object.
When you need to reference those extra fields in the javascript, you need to reference extendedProps like below in the eventClick handler. For setting the "description" of my event to show in the body of my popup modal display, you reference the info.event.extendedProps.description.
<script type="text/javascript">
let calendar = initCalendar();
function initCalendar() {
var calendarEl = document.getElementById('calendar');
let calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
weekNumbers: true,
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
eventClick: function (info) {
document.getElementById('Title').innerHTML = info.event.title;
document.getElementById('Description').innerHTML = info.event.extendedProps.description;
$('#EventDetail').modal('show');
},
events: {
url: '#Url.Action("Calendar")'
}
});
calendar.render();
return calendar;
}
</script>

Related

Events not showing on full calendar

the calendar shows the resources
Here is the code that generates the calendar
var calendarEl = document.getElementById('icalendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
timeZone: 'UTC',
headerToolbar: {
left: 'today prev,next',
center: 'title',
right: 'resourceTimelineDay resourceTimeline2Day resourceTimeline3Day'
},
footerToolbar: {
left: 'today prev,next resourceTimelineDay resourceTimeline2Day resourceTimeline3Day',
center: '',
right: ''
},
initialView: 'resourceTimelineDay',
resourceAreaWidth: '15%',
slotMinTime: '08:00',
slotMaxTime: '21:00',
slotDuration: '00:20:00',
resourceAreaHeaderContent: 'Inspection Calendar',
resources: resources,
events: events,
resourceLabelDidMount: function (arg) {
arg.el.style.background = arg.resource.extendedProps.color;
},
})
calendar.render();
});
I see the json in the console, first array is the resource that shows and the second array is the events
Does anyone know why this would be invalid and not show the event?
I am super confused
Issue was the date didn't match what i was looking for

Event ToolTip not displaying in FullCalendar

I've been working with the FullCalendar configuration for a little bit now but I've reached a point that I just can't get figured out. I want to enable to tooltips to appear when the end user hovers over the event. I would like to give a little further information in the tooltip for the event, such as a phone contact number, etc.
I've tried a number of different options that I was able to find.
The list of links below for example.
FullCalendar event popup
http://jsfiddle.net/m54g5aen/
Fullcalendar / eventdidmount - issue with "more link"
I'll pulling in my events via a JSON array from a PHP script.
Here is my Calendar rendering code.
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
height: 550,
slotDuration: {minutes: 15},
nowIndicator: true,
allDaySlot: false,
eventBackgroundColor: '#916FDF',
slotMinTime: "08:00:00",
slotMaxTime: "20:00:00",
displayEventEnd: false,
initialView: 'timeGridWeek',
events: <?php print json_encode($events); ?>,
eventDidMount: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
},
customButtons: {
addNewAppointment: {
text: 'New Appt',
click: function() {
window.location.href="../client/newAppointment.php";
}
}
},
headerToolbar: {
left: 'title',
center: 'dayGridMonth timeGridWeek',
right: 'prev next today addNewAppointment'
}
});
calendar.render();
});
</script>
My PHP to pull the events is as follows:
<?php
require_once('../db_connect.php');
// Check to see if the session is already started.
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$query = 'SELECT
CONCAT(client.cl_fName, " ", client.cl_lName) AS "title",
CONCAT(appointment.sched_date,"T", appointment.start_time) AS "start",
CONCAT(appointment.sched_date,"T", appointment.end_time) AS "end",
CONCAT("TEST", " DESCRIPTION") AS "description"
FROM
appointment, client
WHERE appointment.client_id = client.client_id';
$statement = $db1->prepare($query);
$statement->execute();
$events = $statement->fetchAll();
$statement->closeCursor();
?>
I appreciate all suggestions. Thank you in advance.
Try using a popover instead of a tooltip, it's better than a tooltip if you wanna add more info to it.
change youreventDidMount to
eventDidMount: function (info) {
$(info.el).popover({
title: info.event.title,
placement: 'top',
trigger: 'hover',
content: 'more info on the popover if you want',
container: 'body'
});
}

How to show a description of Events in fullcalendar

How can I show a description of Events in fullcalendar?
I have events that have a title and a description.
So how can I show the description?
When you add the title and description it will concatenate.
Using the below code, you can concatenate with the title:
eventRender: function (event, element, view) {
element.find('.fc-title').append('<div class="hr-line-solid-no-margin"></div><span style="font-size: 10px">' + event.description + '</span></div>');
},
Here is the working jQuery or JavaScript code.
I love Bootbox.js for showing message so I implemented that also here:
$(document).ready(function() {
var today_date = moment().format('YYYY-MM-DD');
console.log(today_date);
// $('#calendar').fullCalendar('gotoDate', today_date);
$('#calendar').fullCalendar({
theme: false,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek'
// right: 'month,basicWeek,basicDay'
},
// header: { center: 'month,agendaWeek' }, // Buttons for switching between views
defaultDate: today_date,
businessHours:
{
rendering: 'inverse-background',
dow: [0,1]
},
editable: false,
eventLimit: true, // Allow "more" link when too many events
events: myevents,
eventRender: function (event, element) {
element.attr('href', 'javascript:void(0);');
element.click(function() {
bootbox.alert({
message: 'Description : '+event.description,
title: event.title,
});
});
}
});
});

JSON Query or JavaScriptSerializer for FullCalendar

Using the fullcalendar JQuery Model,
Works perfectly if I manually enter the javascript objects:
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
theme:true,
events : [
{
title: 'Event1',
start: '2014-03-12'
},
{
title: 'Event2',
start: '2014-03-1'
}
// etc...
],
But when I use a JSON or JavaScriptSerializer ashx handler, nothing shows on the calendar. Am I missing something? or have I made a stupid error:
Code from page calling JSON or JavaScript - I actually get objects back and can see them but not on calendar:
events:
{
url: $("#ASHXHandlerTextBox").val(),
type: 'POST',
data: {
startdate: $("#StartDateTextBox").val(),
calendar: $("#CalendarToUseTextBox").val(),
userid: $("#UserIdTextBox").val()
},
error: function() {
alert($("#ASHXHandlerTextBox").val());
},
success: function (data) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
alert(key + " -> " + data[key]);
}
}
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
});
Code from "ashx JavaScriptSerializer" file:
JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(new
{
items = new[] {
new {title = "command" , start = "Wed, 12 Mar 2014 "},
new {title = "command2" , start = "Thu, 13 Mar 2014 "}
}
}));
Code from ashx JSON Handler:
context.Response.Write(JsonConvert.SerializeObject(new
{
items = new[] {
new {title = "command" , start = "2014-03-12"},
new {title = "command2" , start = "2014-03-13"}
}
}));
Any Ideas?

click prev/next and load new data

I have fullcalendar working fine loading data using json from a flatfile(s).
I would like to load each months data from that months file on clicking prev/next.
Using ajax? events: function( start, end, callback ) addEventSource - removeEventSource? other?
Allow that jQuery is still a work in progress for me.
UPDATE:
I have set:
viewDisplay: function(view) { var next = view.title; alert(next); },
which gives me Month Year on clicking next/prev
How to parse this to json-events.php
I tried [split next] events: "json-events.php?month=month",
nope...
This is not using php, but you can change the AJAX call in getCalData() to do it.
EventSource will be filled with the next data.
I hope this helps a little bit.
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'resourceMonth'
},
defaultView: 'resourceWeek',
eventSources: [ getCalData() ],
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
viewDisplay: function (view) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', getCalData());
$('#calendar').fullCalendar('rerenderEvents');
}
});
});
function getCalData() {
var source = [{}];
$.ajax({
async: false,
url: '/mysite/GetWeekData',
data: { myParam: $('#calendar').fullCalendar('getView').visStart },
success: function (data) {
$(data).each(function () {
source.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
});
});
},
error: function () {
alert('could not get the data');
},
});
return source;
}
fullcalendar by default send 2 additional parameters when getting events, params[:start], params[:end]
u can use them to return queried events between these 2 values
you can just add View Render property to configuration Object of fullcalendar
viewRender: function(view, element) {
//console.debug("View Changed: ",view.start, view.end);
// events = loadevents();
jQuery(nativeelement).fullCalendar('removeEvents');
jQuery(nativeelement).fullCalendar('addEventSource', events);
}
now you can load month by month.
This syntax for angular2

Resources