Is there a way to prevent overlapping events in jQuery FullCalendar?
12 Answers
I made a function that checks whether the given event is overlapping other or not. Returns true if the event is overlapping other and false otherwise.
function isOverlapping(event){
var array = calendar.fullCalendar('clientEvents');
for(i in array){
if(array[i].id != event.id){
if(!(Date(array[i].start) >= Date(event.end) || Date(array[i].end) <= Date(event.start))){
return true;
}
}
}
return false;
}
You can use it when dropping or resizing and event and if the event overlaps other use the revertFunc that is received in the eventDrop and eventResize callbacks or cancel the creation of an event in the select callback. In order to use it in the select callback create a dummie event:
var event = new Object();
event.start = start;
event.end = end;
-
It's really great! It would be even faster it the array is `filter`ed with the `view.start` and `view.end` – Thiru Dec 19 '13 at 12:00
-
This could also help, special case, but still shows how to find a solution: http://stackoverflow.com/a/29832834/1066234 – Avatar Apr 24 '15 at 06:18
-
This does not seem to work with the latest Fullcalendar, I used this instead: http://stackoverflow.com/a/15804896/1066234 – Avatar Dec 16 '15 at 13:10
-
Works great in the latest FullCalendar!! Thanks :) – olefrank Nov 17 '16 at 10:23
-
nice function, to update: fullCalendar array gives you dates as Date, so you don't have to Date(array[i].start), just with the value is good enough array[i].start – absolutkarlos Aug 05 '20 at 20:44
As of version 2.20 this change has been incorporated by default...
use
eventOverlap: false

- 29
- 7

- 363
- 2
- 18
-
1Will you please tell me where to set the code "eventOverlap: false" – Sam Hanson Jan 10 '17 at 10:11
Same as ecruz's answer but with logic that worked better for me.
function isOverlapping(event){
// "calendar" on line below should ref the element on which fc has been called
var array = calendar.fullCalendar('clientEvents');
for(i in array){
if (event.end >= array[i].start && event.start <= array[i].end){
return true;
}
}
return false;
}

- 400
- 3
- 7
use this
eventOverlap: false, // when load event
selectOverlap: false, // when create event from calender
for reference :

- 91
- 5
Just add
eventOverlap: false
as one of your options outside of the events element.
You can also add the option
overlap
to a single event, which will override the eventOverlap on that single event.
events: [
{
title : 'event1',
start : '2017-05-27'
},
{
title : 'event2',
start : '2017-05-28',
end : '2017-05-29'
},
{
title : 'event3',
start : '2017-05-30T12:30:00',
allDay : false, // will make the time show
draggable: true,
editable: true,
overlap: true,
},
{
title : 'event3',
start : '2017-05-30T09:30:00',
allDay : false, // will make the time show
draggable: true,
editable: true,
}
],
eventOverlap: false

- 1
- 1

- 4,851
- 9
- 47
- 82
Same as Matthew Webb but Following worked for me since sometimes my end date was null when i was dragging the event from allDay to some time slot
function isOverlapping(event) {
var arrCalEvents = $('#' + g_str_FullCalenderID).fullCalendar('clientEvents');
for (i in arrCalEvents) {
if (arrCalEvents[i].id != event.id) {
if ((event.end >= arrCalEvents[i].start && event.start <= arrCalEvents[i].end) || (event.end == null && (event.start >= arrCalEvents[i].start && event.start <= arrCalEvents[i].end))) {//!(Date(arrCalEvents[i].start) >= Date(event.end) || Date(arrCalEvents[i].end) <= Date(event.start))
return true;
}
}
}
return false;
}

- 316
- 3
- 16
-
And how do I use this? I read ecruz details, I used it in eventDrop, but didn't worked. – machineaddict Jun 02 '14 at 12:42
-
@machineaddict: You could use it in eventDrop as well as in eventResize. It would be more easy to help if you post your code. – Mantra Jun 27 '14 at 09:56
-
this is my code http://pastebin.com/8jyQwpbH. As it is right now, is working very good, except I can have events that are overlapping. – machineaddict Jun 30 '14 at 07:07
-
I finally made it work, if someone might need it. I'm using Fullcalendar 2.0.0. [Here is the code](http://pastebin.com/DRXDwKNP). – machineaddict Oct 23 '14 at 10:30
eventResize: function (event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view) {
var start = new Date(event.start);
var end = new Date(event.end);
var events = event.source.events;
for (var i = 0; i < events.length; i++) {
var someEvent = events[i];
if (someEvent._id == event._id)
{
continue;
}
var seStart = new Date(someEvent.start);
var seEnd = new Date(someEvent.end);
if ((start < seEnd) && (seStart < end)) {// dates overlap
revertFunc();
}
}
},

- 41
- 8
I'm using version 2.11 of Fullcalendar and i made some change to code posted by ecruz:
function isOverlapping(event){
var array = calendar.fullCalendar('clientEvents');
for(i in array){
if(array[i]._id != event._id){
if(!(array[i].start.format() >= event.end.format() || array[i].end.format() <= event.start.format())){
return true;
}
}
}
return false;
}
and this is how i use to prevent the overlap:
$('#calendar').fullCalendar({
...
eventDrop: function(event, delta, revertFunc) {
if (isOverlapping(event)) {
revertFunc();
}
},
...
});

- 4,972
- 3
- 25
- 39

- 157
- 1
- 5
just try this, works fine for me.... https://fullcalendar.io/docs/event_ui/eventOverlap/
eventOverlap: function(stillEvent, movingEvent) {
return stillEvent.allDay && movingEvent.allDay;
}

- 109
- 1
- 4
Please write like this.
$('#calendar').fullCalendar({
selectOverlap: false,
eventOverlap:false,
})
SelectOverlap prevent overlap when we create an event overlapping.
EventOverlap prevent overlap when we drag drop an event overlapping.

- 162
- 3
- 9
allowCalEventOverlap: [boolean | default: false] – Whether the calendar will allow events to overlap. Events will be moved or resized if necessary if they are dragged or resized to a location that overlaps another calendar event.
is that what you were looking for?

- 127
- 1
- 10
-
3I think this is for jQuery Week Calendar ;) It doesn't work with jQuery FullCalendar. – user267637 Mar 03 '10 at 08:37
-
haha yeah just figured the same thing, sorry. maybe your answer is in here; http://code.google.com/p/fullcalendar/issues/detail?id=218 – Eggie Mar 03 '10 at 08:45