Display more Text in fullcalendar

JavascriptHtmlFullcalendar

Javascript Problem Overview


I am looking for a solution to display more information in event.

For example in the DayView you see a event from 06:00 to 10:00.
I want to display a additional description in this event (not only the time and the title).

Javascript Solutions


Solution 1 - Javascript

This code can help you :

$(document).ready(function() { 
	$('#calendar').fullCalendar({ 
		events: 
			[ 
				{ 
					id: 1, 
					title: 'First Event', 
					start: ..., 
					end: ..., 
					description: 'first description' 
				}, 
				{ 
					id: 2, 
					title: 'Second Event', 
					start: ..., 
					end: ..., 
					description: 'second description'
				}
			], 
		eventRender: function(event, element) { 
			element.find('.fc-title').append("<br/>" + event.description); 
		} 
	});
}	

Solution 2 - Javascript

I personally use a tooltip to display additional information, so when someone hovers over the event they can view a longer descriptions. This example uses http://craigsworks.com/projects/qtip/"> qTip, but any tooltip implementation would work.

$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $('#calendar').fullCalendar({
        header: {
            left: 'prev, next today',
            center: 'title',
            right: 'month, basicWeek, basicDay'
        },
        //events: "Calendar.asmx/EventList",
        //defaultView: 'dayView',
        events: [
	    {
	        title: 'All Day Event',
	        start: new Date(y, m, 1),
	        description: 'long description',
	        id: 1
	    },
	    {
	        title: 'Long Event',
	        start: new Date(y, m, d - 5),
	        end: new Date(y, m, 1),
	        description: 'long description3',
	        id: 2
	    }],
        eventRender: function(event, element) {
            element.qtip({
                content: event.description + '<br />' + event.start,
                style: {
                    background: 'black',
                    color: '#FFFFFF'
                },
                position: {
                    corner: {
                        target: 'center',
                        tooltip: 'bottomMiddle'
                    }
                }
            });
        }
    });
});

Solution 3 - Javascript

With the modification of a single line you could alter the fullcalendar.js script to allow a line break and put multiple information on the same line.

In FullCalendar.js on line ~3922 find htmlEscape(s) function and add .replace(/<br\s?/?>/g, '
') to the end of it.

function htmlEscape(s) {
    return s.replace(/&/g, '&amp;')
	.replace(/</g, '&lt;')
	.replace(/>/g, '&gt;')
	.replace(/'/g, '&#039;')
	.replace(/"/g, '&quot;')
	.replace(/\n/g, '<br />')
	.replace(/&lt;br\s?\/?&gt;/g, '<br />');
}

This will allow you to have multiple lines for the title, separating the information. Example replace the event.title with title: 'All Day Event' + '<br />' + 'Other Description'

Solution 4 - Javascript

as a possible solution: Add some extra more content to the title. Overwrite this css style:

 .fc-day-grid-event .fc-content {
   white-space: normal; 
}

Solution 5 - Javascript

Here's my code for popup using qTip2 and eventMouseover:

$(document).ready(function() {
	// Setup FullCalendar
    // Setup FullCalendar
    (function() {
    	var date = new Date();
    	var d = date.getDate();
    	var m = date.getMonth();
    	var y = date.getFullYear();
    	var day=date.toLocaleDateString(); 
    
    	var tooltip = $('<div/>').qtip({
    		id: 'fullcalendar',
    		prerender: true,
    		content: {
    			text: ' ',
    			title: {
    				button: true
    			}
    		},
    		position: {
    			my: 'bottom center',
    			at: 'top center',
    			target: 'mouse',
    			viewport: $('#fullcalendar'),
    			adjust: {
    				mouse: false,
    				scroll: false
    			}
    		},
    		show: false,
    		hide: false,
    		style: 'qtip-light'
    	}).qtip('api');
    
    	$('#fullcalendar').fullCalendar({
    		editable: true,
    		 disableDragging: true,
    		height: 600,
    		header: {
    			left: 'title',
    			center: '',
    			right: 'today prev,next'
    		},
    		
            dayClick: function() { tooltip.hide() },
    		eventResizeStart: function() { tooltip.hide() },
    		eventDragStart: function() { tooltip.hide() },
    		viewDisplay: function() { tooltip.hide() },
    		events: [
    			{
    				title: 'All Day Event',
    				start: new Date(2014, 3, 1)
    			},
    			{
    				title: 'Long Event',
    				start: new Date(y, m, d-5),
    				end: new Date(y, m, d-2)
    			},
    			{
    				id: 999,
    				title: 'Repeating Event',
    				start: new Date(y, m, d+4, 16, 0),
    				allDay: false
    			},
    			{
    				title: 'Meeting',
    				start: new Date(y, m, d, 10, 30),
    				allDay: false
    			},
    			{
    				title: 'Spring Membership Conference',
    				start: new Date(y, m, d+6, 7,0),
    				end: new Date(y, m, d+6, 13,0),
    				allDay: false,
    				description:'save the date! Join us for our Annual Membership Conference. Breakfast will be served beginning at 7:30 a.m. Featuring The EFEC Belief System & Our Pledge lunch'
    			},
    			{
    				title: 'Birthday Party',
    				start: new Date(y, m, d+1, 19, 0),
    				end: new Date(y, m, d+1, 22, 30),
    				allDay: false
    			}
    		],
    		eventMouseover : function(data, event, view) {
    			var content = 
    			'<p>'+data.description +'<p>'+
    			'<h3>'+data.title+'</h3>' + 
    				'<p><b>Start:</b> '+data.start+'<br />' + 
    				(data.end && '<p><b>End:</b> '+data.end+'</p>' || '');
    
    			tooltip.set({
    				'content.text': content
    			})
    			.reposition(event).show(event);
    		},
    	});
    }());
});

Solution 6 - Javascript

I needed the ability to display quite a bit of info (without a tooltip) and it turned out quite nice. I used FullCalendars title prop to store all my HTML. The only thing you have to do to ensure it works after render is to parse the title fields HTML.

// `data` ismy JSON object.
$.each(data, function(index, value) {
  value.title = '<div class="title">' + value.title + '</div>';
  value.title += '<div class="deets"><span class="time"><img src="/themes/custom/bp/images/clock.svg">' + value.start_time + ' - ' + value.end_time + '</span>';
  value.title += '<span class="location"><img src="/themes/custom/bp/images/pin.svg">' + value.location + '</span></div>';
  value.title += '<div class="learn-more">LEARN MORE <span class="arrow"></span></span>';
});

// Initialize the calendar object.
calendar = new FullCalendar.Calendar(cal, {
  events: data,
  plugins: ['dayGrid'],
  eventRender: function(event) {
    // This is required to parse the HTML.
    const title = $(event.el).find('.fc-title');
    title.html(title.text());
  }
});
calendar.render();

I would have used template literals, but had to support IE11

calender

Solution 7 - Javascript

For some reason, I have to use

element.find('.fc-event-inner').empty();

to make it work, i guess i'm in day view.

Solution 8 - Javascript

Well i found a simpler solution for me:

I changed fullcalendar.css

and added the following:

float: left;
clear: none;
margin-right: 10px;

Resulting in:

.fc-event-time,
.fc-event-title {
    padding: 0 1px;
    float: left;
    clear: none;
    margin-right: 10px;
}

now it only wraps when it needs to.

Solution 9 - Javascript

I would recommend the use of the eventAfterRender callback instead of eventRender. Indeed if you use eventRender you might jeopardize the correct display of the events, in coffee script, it something like :

$("#calendar").fullCalendar
    eventAfterRender: (event, element) ->
        element.find('.fc-title').after("<span>"+event.description+"</span>")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchichiView Question on Stackoverflow
Solution 1 - JavascriptEurekaView Answer on Stackoverflow
Solution 2 - JavascriptJake1164View Answer on Stackoverflow
Solution 3 - JavascriptJake1164View Answer on Stackoverflow
Solution 4 - JavascriptDolceVitaView Answer on Stackoverflow
Solution 5 - JavascriptsunilkjtView Answer on Stackoverflow
Solution 6 - JavascriptRonnieView Answer on Stackoverflow
Solution 7 - JavascriptwindmaomaoView Answer on Stackoverflow
Solution 8 - Javascriptuser1641172View Answer on Stackoverflow
Solution 9 - JavascriptSylvain Martin Saint LéonView Answer on Stackoverflow