Ish Ish - 2 months ago 9
jQuery Question

fullcalendar showing wrong date

This is my event array :

[Object { title="Event1", start="2016-09-14"}, Object { title="Event2", start="2016-09-06"}]


Event 1 is showing on 2016-09-12 and event 2 is showing on 2016-09-05

$('#calendar').fullCalendar({
header: {
left: 'prev,next',
center: 'title',
right: 'month,basicWeek,basicDay'
},
viewRender: function (view, element) {
var add_url = '<a class="add-task" href="#" title="Assign Applicant"><i class="fa fa-plus-square"></i></a>';
$(".fc-day-number").after(add_url);
},
editable: true,
events: getEvent,
dayClick: function () {
// alert('a day has been clicked!');
}
});

Answer

I reproduced the issue. The error is in viewRender function. After removing it dates are shown as expected.

First of all, this is wrong (the error is specifically in this line):

$(".fc-day-number").after(add_url);

because you need to refer to specific event.

Second, viewRender is not the right function to use because it's intended for rendering whole view.

For adding custom buttons you can use eventAfterRender:

eventAfterRender: function(event, element, view) { 
    var add_url = '<a class="add-task" href="#" title="Assign Applicant"><i class="fa fa-plus-square"></i></a>';
    element.after(add_url);
},