Can I prevent events with conflict time?

落爺英雄遲暮 提交于 2019-11-27 07:20:28

问题


How can I prevent events with conflict time? Is there any variable to set up?


回答1:


No, there is not a variable to set, but you can use something like clientEvents which retrieves events that fullcalendar has in memory. You can use the function below in the eventDrop. In the case below it uses a function to filter out whether the event will have have an overlap or not.

function checkOverlap(event) {  

    var start = new Date(event.start);
    var end = new Date(event.end);

    var overlap = $('#calendar').fullCalendar('clientEvents', function(ev) {
        if( ev == event)
            return false;
        var estart = new Date(ev.start);
        var eend = new Date(ev.end);

        return (Math.round(estart)/1000 < Math.round(end)/1000 && Math.round(eend) > Math.round(start));
    });

    if (overlap.length){  
            //either move this event to available timeslot or remove it
       }                  
  }



回答2:


Correct overlap checking.

        eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view) {
            /// deny overlap of event
            var start = new Date(event.start);
            var end = new Date(event.end);

            var overlap = $('#calendar').fullCalendar('clientEvents', function(ev) {
                if( ev == event) {
                    return false;
                }
                var estart = new Date(ev.start);
                var eend = new Date(ev.end);

                return (
                    ( Math.round(start) > Math.round(estart) && Math.round(start) < Math.round(eend) )
                    ||
                    ( Math.round(end) > Math.round(estart) && Math.round(end) < Math.round(eend) )
                    ||
                    ( Math.round(start) < Math.round(estart) && Math.round(end) > Math.round(eend) )
                );
            });
            if (overlap.length){
                revertFunc();
                return false;
            }
        }



回答3:


you can add eventOverlap : false in the celendar config, http://fullcalendar.io/docs/event_ui/eventOverlap/




回答4:


Add custom property in the event object overlap:false for example your event object will be

                 `{
                    title:'Event',
                    start: '2017-01-04T16:30:00',
                    end: '2017-01-04T16:40:00',
                    overlap:false
                  }`

Now override selectOverlap function,

selectOverlap: function(event) {
    if(event.ranges && event.ranges.length >0) {
      return (event.ranges.filter(function(range){
          return (event.start.isBefore(range.end) &&
                  event.end.isAfter(range.start));
      }).length)>0;
    }
    else {
      return !!event && event.overlap;
    }
  },

It will not let the another event to override the already placed event.




回答5:


This does the trick. It also handles resizing overlapping events

var calendar = new Calendar(calendarEl, {
      selectOverlap: false,
      eventOverlap: false
  }
});


来源:https://stackoverflow.com/questions/15800398/can-i-prevent-events-with-conflict-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!