FullCalendar: Remove day spanning for events in the month view

Is there a way to remove day spanning for events in the month view only ?

I've got events that starts at 9PM and ends at 3AM that show up spanning 2 days in the month view but I would like to have them in a single day cell. I would still be able to have them span multiple days in the agendaWeek and agendaDay view at the same time.

I've tried messing around with the positioning and sizing of the events in eventAfterRender but it creates holes for the other days where the span should have happened, ie. FullCalendar will still position other events as if the day spanning occured. I would have to do the whole position and size computation for everything if I were to go that route.

I could change the actual start and end datetime value of the events when in the month view but I would have to update them again when going in the other views.

Is there an easy way to do this? Am I missing something?

Thanks


I dug up into the internals of FullCalendar and figured out how segments are used to compute events position, size and day spanning. I figured that if I could change some of the segments values before their size are computed, I could do exactly what I needed here. I added a new event in FullCalendar to be able to transform those segments:

--- a/fullcalendar.js   Mon Jan 27 14:22:35 2014 -0500
+++ b/fullcalendar.js   Mon Jan 27 16:11:45 2014 -0500
@@ -5196,6 +5196,9 @@
        var html;
        var elements;

+       // call the trigger with the segments
+       trigger('segmentTransform', this, segments);
+
        // calculate the desired `left` and `width` properties on each segment object
        calculateHorizontals(segments);

I used that new event to transform the segments when I needed it. The resulting code looks something like this:

// In my Full Calendar options
segmentTransform: function(segments, view) {
    if (view.name == 'month') {
        var curEvents = {};
        var segmentsToRemove = [];
        for (var i in segments) {
            var segment = segments[i];
            var eventId = segment.event.id;

            if (eventId in curEvents) {
                segmentsToRemove.push(i);
                continue;
            }
            curEvents[eventId] = true;

            if (segment.leftCol != segment.rightCol) {
                segment.rightCol = segment.leftCol;
            }
            segment.isEnd = true;
        }

        segmentsToRemove.reverse();
        for (var i in segmentsToRemove) {
            var indexToRemove = segmentsToRemove[i];
            segments.splice(indexToRemove, 1);
        }
    }
}

This was for version 1.6.4


You need to put check on time. if time is extending to next day. round it to 11:59 AM current day before passing it to fullcalendar, and display the actual timings of the event in the title.

链接地址: http://www.djcxy.com/p/14260.html

上一篇: 跨越多天的事件在fullcalendar中无法正确显示

下一篇: FullCalendar:删除月视图中事件的日期范围