Search code examples
jqueryfullcalendarviewrendering

FullCalendar viewRender: Append text in listDay-View


I'm using FullCalendar by Adam Shaw.

To show all events on a day, I'm using the listday-view. I need to show a link in the header of the table.

I tried the following code, but it doesn't work.

viewRender: function (view, element) {  
    if(view.name === 'listDay') {
        element.find('.fc-widget-header').append( '<span>&raquo; My Text</span>' );
    }
}

It seems, that the element is not been found. A "jQuery-alert" instead of the "element.find" works.


Solution

  • That's because the viewRender callback runs before the .fc-widget-header element has been rendered and can't be found. https://fullcalendar.io/docs/display/viewRender/

    You can add your code in the eventAfterAllRender callback because as i can see the listDay will rendered only if there are events to show.

    example

    eventAfterAllRender : function (view) {  
        if(view.name === 'listDay') {
            view.el.find('.fc-widget-header').append( '<span>&raquo; My Text</span>' );
        }
    }