Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data to background event object in FullCalendar

Is there a way to get a data that I passed to eventObj when user clicks on background event? My sample background event looks like this:

{
 id: 'availableForMeeting',
 title: 'Test Background Event #1',
 start: '2015-08-13T07:30:00',
 end: '2015-08-13T12:30:00',
 rendering: 'background',
 sampleId: 214,
 color: 'red'
}

But I can't get sampleId field, 'cause it doesn't exist in jsEvent.

like image 319
Nikita Bayev Avatar asked Nov 21 '25 21:11

Nikita Bayev


1 Answers

First, in order to actually get a click handler on a background event, you have to use a delegated jquery .on() because FullCalendar's eventClick doesn't work for background events.

$("#calendar").on("click",".fc-bgevent",function(event){
    console.log($(this).data());
});

With just that, you will get an empty console log. We need to add the event data to the event element. We can do this in eventRender

eventRender: function(event,element,view){
    $(element).data(event);
},

Working JSFiddle

like image 164
DanielST Avatar answered Nov 24 '25 06:11

DanielST