FullCalendar - hide certain hours in day view - fullcalendar

I'm using the jQuery FullCalendar plugin and want to hide certain hours in day view.
I want to show the calendar from 6am to 10am and from 12pm to 4pm.
I already set minTime: '6:00' and maxTime: '14:00' but I also need to hide the hours between 10am to 12pm too.

The problem is, fullcalendar relies on Moment.js durations. As far as I can tell, you can't have a duration that is multiple durations.
However, it seems that fullcalendar renders the agenda first, then calculates the position of where the events need to be after the agenda is laid out. So, if a CSS solution is acceptable, you could always do the following:
[data-time^="10"]>td, [data-time^="11"]>td, [data-time^="12"]>td
{
height: 0 !important;
border: 0 !important;
}
This works by matching the table row's "data-time" attribute. The match pattern is a prefix match, to save some typing. If you don't want to use ^= to match the prefix, you can try these:
https://www.w3.org/TR/css3-selectors/#selectors
Edit to demonstrate (works on Chrome 52). As you can see, I also needed to make the children of the affected cells hidden (display: none;). Also note that you'll need to filter your own data to exclude or alter dates times that fall in that range. I've included some events that show what happens if you don't take this precaution.
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay'
},
defaultView: 'agendaDay',
defaultDate: '2016-06-12',
editable: true,
eventLimit: true,
events: [
{
title: 'Meeting',
start: '2016-06-12T10:30:00',
end: '2016-06-12T12:30:00'
},
{
title: 'Loooong Meeting',
start: '2016-06-12T09:30:00',
end: '2016-06-12T14:30:00'
},
{
title: 'Lunch',
start: '2016-06-12T12:00:00'
},
{
title: 'Meeting',
start: '2016-06-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2016-06-12T17:30:00'
},
{
title: 'Dinner',
start: '2016-06-12T20:00:00'
}
]
});
})
[data-time^="10"]>td,
[data-time^="11"]>td,
[data-time^="12"]>td
{
height: 0 !important;
border: 0 !important;
}
[data-time^="10"]>td *,
[data-time^="11"]>td *,
[data-time^="12"]>td *
{
display: none !important;
}
<link href="http://fullcalendar.io/js/fullcalendar-2.9.1/fullcalendar.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="http://fullcalendar.io/js/fullcalendar-2.9.1/fullcalendar.min.js"></script>
<div id="calendar"></div>

Related

Fullcalendar: Show additional event data in list view

I'm using fullcalendar to display a month view which shows the time and title of events (and a popover showing the description when hovered). When I click the event, I show a listday view that shows all the events for that day. That all works fine and I have this working with this code:
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
start: 'dayGridMonth,listDay',
center: 'title',
end: 'prev,next'
},
initialView: 'dayGridMonth',
initialDate: '2023-01-12',
height: 'auto',
dayMaxEvents: 3,
moreLinkClick: 'listDay',
eventClick: function(info){
switchToListView(info)
},
eventColor: 'green',
views: {
listDay: {
displayEventEnd: true
}
},
events: [
{
title: 'All Day Event',
start: '2023-01-01'
},
{
title: 'Meeting',
description: 'My Description',
start: '2023-01-12T10:30:00',
end: '2023-01-12T12:30:00'
},
and in this code pen
I'd like to show the description text for the event in addition to the title in the listday view and I can't figure out how to do this. I don't know whether I need to use an event hook or what. I just can't make my way through the docs and examples to see what to do.
Appreciate any help.
I got this working with this use of eventDidMount.
eventDidMount: function(info) {
info.el.querySelector('.fc-list-event-title a').innerHTML += ` ${info.event.extendedProps.description}`
},
Frankly, it feels a little weird that I need to go into the depths of the rendered HTML to adjust the output instead of changing what is going INTO the generated HTML but I guess that's just how it works (??)
Thanks to #ADyson for the push in the right direction.

How to change size of event element in FullCalendar DayGrid View?

In my FullCalendar rendering I use the dayGrid view to create a schedule. When populating this calendar view (schedule) with events, every event is the same height, regardless of the duration of the event. I would like to make the events bigger or smaller based on their duration, similar to what the FullCalendar demo shows for other calendar views. Is this possible to achieve using the dayGrid View?
My Calendar:
FullCalendar Desired Styling:
In v5 find in the CSS file .fc-h-event and add the height option. This is mine:
.fc-h-event { /* allowed to be top-level */
display: block;
height: 70px !important;
border: 2px solid #3788d8;
border: 2px solid var(--fc-event-border-color, #3788d8);
background-color: #3788d8;
background-color: var(--fc-event-bg-color, #3788d8)
}
I ended up finding a way to accomplish my goal. The CSS styling for the calendar rendering can be modified right in the html page using:
<style>
.fc-day-grid-event > .fc-content {
white-space: normal;
}
</style>
This allows the text of the event title to wrap onto multiple lines. Without modifying this styling the event text (title) just cuts off anything longer than the width of the event box.
Once this styling is in place, I can just insert newline characters ('\n') into my html in order to expand the size of the box. Because I am controlling my events from a database, it is easy to simply add newline characters into the title string corresponding to the desired size of the event.
Here is what my calendar looked like before:
And here are some sample events to recreate the image:
events: [
{
id: 'event1',
title: 'Event 1- 5h',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
},
{
id: 'event2',
title: 'Event 2- 2h',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
},
{
id: 'event3',
title: 'Event 3- 1h',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
}
]
Here is what the calendar looks like using my solution:
And the simple modification to the events needed for this solution:
events: [
{
id: 'event1',
title: 'Event 1- 5h' + '\n\n\n\n\n',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
},
{
id: 'event2',
title: 'Event 2- 2h' + '\n\n',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
},
{
id: 'event3',
title: 'Event 3- 1h',
start: '2020-06-16',
displayEventTime: false,
editable: true,
allDay: true
}
]

Error displaying an event between two months

I'm having problems with the nextDayThreshold option. Even when I´m setting it to "08:00:00", FullCalendar is duplicating events that finish at "07:00:00" on the 1st of a month, displaying it with a left arrow in timelineMonth, showing the same event in two months:
$(function() { // document ready
$('#calendar').fullCalendar({
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
nextDayThreshold: '08:00:00',
header: {
left: 'today prev,next',
center: 'title',
right: 'timelineMonth'
},
defaultView: 'timelineMonth',
resourceColumns: [
{
labelText: 'first column',
field: 'title',
width: 150
}
],
resources: [{
id: 'a',
title: 'Auditorium A',
}, {
id: 'b',
title: 'Auditorium B',
eventColor: 'green'
}, {
id: 'c',
title: 'Auditorium C',
eventColor: 'orange'
}],
events: [{
id: '1',
resourceId: 'b',
start: '2018-10-31T21:00:00',
end: '2018-11-01T07:00:00',
title: 'event 1'
}]
});
});
Fiddle
Is this a bug?
Short answer: No, it's not a bug.
Long answer:
The documentation for nextDayThreshold says:
Only affects timed events that appear on whole-days. Whole-day cells
occur in month view, basicDay, basicWeek and the all-day slots in the
agenda views.
In a "timeline" view, even though the slotDuration is set to 1 day by default in a "timelineMonth" view, fullCalendar still regards these as timed slots, rather than whole-day cells. Therefore the nextDayThreshold rules do not apply. e.g. If you changed to a timelineWeek view, it still uses exactly the same layout and slots, except the slots have a different length. They're not a different kind of cell.
If we look at an updated version of your fiddle: https://jsfiddle.net/q2fk57nb/6/ which now includes a regular "month" view (I simply added right: 'timelineMonth,month' to the header) we can see that the same event in that view is confined to the 31st October, because of the nextDayThreshold rule, and the fact that the regular "month" view uses "whole-day" cells.

can't display as same as demo code with fullcalendar

I tried to apply fullcalendar to my page.
When I pasted the example code to my page, there's no header buttons and no same event styles, these events can't be drag and drop.
Using: jquery 3.3.0, moment 2.20.1, fullcalendar 3.8.0.
Do I lost some settings? Please help and figure out, thank you all.
$(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
defaultDate: '2018-01-12',
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2018-01-01'
},
{
id: 999,
title: 'Repeating Event',
start: '2018-01-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2018-01-16T16:00:00'
},
{
title: 'Conference',
start: '2018-01-11',
end: '2018-01-13'
},
{
title: 'Meeting',
start: '2018-01-12T10:30:00',
end: '2018-01-12T12:30:00'
},
{
title: 'Lunch',
start: '2018-01-12T12:00:00'
},
{
title: 'Meeting',
start: '2018-01-12T14:30:00'
},
{
title: 'Dinner',
start: '2018-01-12T20:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2018-01-28'
}
]
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.0/fullcalendar.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.0/fullcalendar.print.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.0/fullcalendar.min.js"></script>
<div id="calendar">
</div>
I don't know precisely which example code you tried to copy, but unfortunately you didn't copy it exactly right.
This is your problem:
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.0/fullcalendar.print.min.css" rel="stylesheet" />
This overrides the default CSS (from fullcalendar.min.css) with the version intended for use when printing the page. Changes here include hiding the headers and buttons and reducing the use of colours.
What you need to do is tell the browser to only use this stylesheet when in print mode. This is done using a media query media="print", as follows:
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.0/fullcalendar.print.min.css" rel="stylesheet" media="print"/>

Fullcalendar event cell background color

I'm using Fullcalendar with a Google Calendar so I can't apply a class to an event as far as I'm aware.
What I want to do should be quite simple and I'm sure the answer will involve eventRender but I just can't get it working.
Simply: change the entire background color of the cell that contains any event (all events are "all day" within the Google Calendar).
What I'm trying to achieve is an "availability" state; any event is "unavailable" i.e. background color red.
Yes, you can do it with eventRender. You'll have to find the td that contains that event. If you inspect the fullCalendar, you'll note the tds have a data-date attribute for that particular day. That is how we will find the td that has an event in it so we can change the background color to red, specifically using:
eventRender: function (event, element) {
var dataToFind = moment(event.start).format('YYYY-MM-DD');
$("td[data-date='"+dataToFind+"']").addClass('activeDay');
}
In this example, the first line in eventRender uses moment to format the event start date into the format needed to match the data-date attribute value. The second line finds a td with the data-date attribute having a value of dataToFind and then adds a class we make up called activeDay, assuming you add something like this to your head/stylesheet:
<style>
.activeDay {background-color:#ff0000 !important;}
</style>
$('#fullCal').fullCalendar({
events: [{
title: 'Main Event 1',
start: new Date(),
end: new Date(),
allDay: false
}, {
title: 'Main Event 2',
start: '2014-10-03 19:00',
end: '2014-10-03 19:30',
allDay: false
}, {
title: 'Main Event 3',
start: '2014-10-15 17:00',
end: '2014-10-15 18:00',
allDay: false
}, {
title: 'Main Event 4',
start: '2014-11-30 7:00',
end: '2014-11-30 18:00',
allDay: false
}, ],
header: {
left: '',
center: 'prev title next',
right: ''
},
eventRender: function(event, element) {
var dataToFind = moment(event.start).format('YYYY-MM-DD');
$("td[data-date='" + dataToFind + "']").addClass('activeDay');
}
});
.activeDay {
background-color: #ff0000 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script>
<p>Example:</p>
<div id="fullCal"></div>
The answer of #MikeSmithDev does not work if you have events on multiple days.
If you have multiple days use this javascript:
eventRender: function (event, element) {
var start = moment(event.start);
var end = moment(event.end);
while( start.format('YYYY-MM-DD') != end.format('YYYY-MM-DD') ){
var dataToFind = start.format('YYYY-MM-DD');
$("td[data-date='"+dataToFind+"']").addClass('dayWithEvent');
start.add(1, 'd');
}
}
It uses the same principle as MikeSmithDev's, so you must use the same css.

Resources