Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullcalendar event's end time is missing

I run Fullcalendar wih this options

defaultEventMinutes:30,
timeFormat: 'HH:mm { - HH:mm}',

I have some events (30 min long each), but only their start time is shown.

10:00 -  
14:30 -

while dragging an event, its start and endtime appears as i should be.

10:00 - 10:30  
14:30 - 15:00
like image 996
user1930254 Avatar asked Jul 30 '13 00:07

user1930254


People also ask

How do I hide time in fullCalendar?

$('#calendar'). fullCalendar({ displayEventTime : false }); That should hide the start time in the title event.

How do I start and end date in fullCalendar?

We can get start date by getView event with intervalStart. We can get end date by getView event with intervalEnd. var month = $('#calendar'). fullCalendar('getView').

How do I turn off weekends in fullCalendar?

Just go from the startDate to the endDate and check if any of those days are weekends. If so, display the alert / popup and return false. select: (start, end, allDay) => { var startDate = moment(start), endDate = moment(end), date = startDate.


3 Answers

I think the reason is that FullCalendar puts the title into the time div when there's not enough space to show the title on a separate line (which is typically the case when an event only spans 30 minutes). When the time and the title are placed in the same div, FullCalendar only passes the start time to the date formatter.

To make it work you could change line number 4020 in fullcalendar.js (v. 1.6.1) from:

eventElement.find('div.fc-event-time')
                        .text(formatDate(event.start, opt('timeFormat')) + ' - ' + event.title);

to

eventElement.find('div.fc-event-time')
                        .text(formatDates(event.start, event.end, opt('timeFormat')) + ' - ' + event.title);

If you don't want to change the source code of FullCalendar, you could instead look into the eventRender callback.


Updated answer

It's probably better to fix this without changing the source code of FullCalendar, and it's actually pretty simple to do it "the right way". However, the eventRender is not too useful, because FullCalendar collapses the time and title after this callback and our changes would be overwritten.

Luckily there's another callback eventAfterRender which can be used:

eventAfterRender: function(event, $el, view) {
    var formattedTime = $.fullCalendar.formatDates(event.start, event.end, "HH:mm { - HH:mm}");
    // If FullCalendar has removed the title div, then add the title to the time div like FullCalendar would do
    if($el.find(".fc-event-title").length === 0) {
        $el.find(".fc-event-time").text(formattedTime + " - " + event.title);
    }
    else {
        $el.find(".fc-event-time").text(formattedTime);
    }
}

Here's an example on jsfiddle: http://jsfiddle.net/kvakulo/zutPu/

like image 163
Regin Larsen Avatar answered Oct 03 '22 16:10

Regin Larsen


The answer of Regin did not work for me (I assume a newer version of FullCalendar).

I've found two solutions.

First, the easiest one that maintains most of the styling for short events. This styles it back to the defaults:

.fc-time-grid-event.fc-short .fc-time span {
    display: inline;
}

.fc-time-grid-event.fc-short .fc-time:before {
    content: normal;
}  

.fc-time-grid-event.fc-short .fc-time:after {
    content: normal;
}

Secondly you could add the following logic to the eventAfterRender. Please note this might have other effects where certain styling of small items will be different, but if this is not a big issue in your environment then this works perfectly.

eventAfterRender: function (event, $el, view) {
                $el.removeClass('fc-short');
            }
like image 27
janpieter_z Avatar answered Oct 03 '22 17:10

janpieter_z


FullCalendar v3.0.0

.fc-time-grid-event.fc-short .fc-time:before {
  content: attr(data-full);
}

.fc-time-grid-event.fc-short .fc-time:after {
  content: normal;
}
like image 36
vijay tanakanakal Avatar answered Oct 03 '22 18:10

vijay tanakanakal