Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom HTML to a jQuery FullCalendar cell

I am using the jQuery FullCalendar (http://arshaw.com/fullcalendar/docs/).

I want to add some custom HTML to each day-cell.

For example in my case I want to have different background colors based on some logic, display a price in the middle...

sample calendar

Is there a way to customize the rendering of a cell?

like image 441
Nathan H Avatar asked Jan 02 '12 14:01

Nathan H


3 Answers

The way I do this is like Conners indicated:

eventRender: function(event, element) {
    element.find(".fc-event-title").remove();
    element.find(".fc-event-time").remove();
    var new_description =   
        moment(event.start).format("HH:mm") + '-'
        + moment(event.end).format("HH:mm") + '<br/>'
        + event.customer + '<br/>'
        + '<strong>Address: </strong><br/>' + event.address + '<br/>'
        + '<strong>Task: </strong><br/>' + event.task + '<br/>'
        + '<strong>Place: </strong>' + event.place + '<br/>'
    ;
    element.append(new_description);
}
like image 101
Gjermund Dahl Avatar answered Oct 16 '22 04:10

Gjermund Dahl


I will explain how I solved this issue for other people.

I used the eventAfterRender callback. In there I used jQuery to parse the "element" parameter and re-write the html before it is sent to the browser.

like image 30
Nathan H Avatar answered Oct 16 '22 04:10

Nathan H


This is the way I dealt with this issue in my application.

In fullcalendar.js, you need to find this:

html +=
    "<span class='fc-event-title'>" +
    htmlEscape(event.title || '') +
    "</span>" +
    "</div>";

This is where the content of the cell is created.

I wanted to have the time of the event on the right side of the cell, so:

html +=
    "<span class='fc-event-title'><div style='float:right'>" + moment(event.start).format('hh:mm a') + "</div>" +
    htmlEscape(event.title || '') +
    "</span>" +
    "</div>";

I am using the momentjs library to format the time.

Now, you can add whatever you want to the calendar cell content, and use standard html to format it.

like image 3
Nicolas Giszpenc Avatar answered Oct 16 '22 04:10

Nicolas Giszpenc