Is there a way to prevent overlapping events in jQuery FullCalendar?

前端 未结 10 2109
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 03:47

Is there a way to prevent overlapping events in jQuery FullCalendar?

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 04:30

    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();
                            }
            },
            ...
        });
    

提交回复
热议问题