Passing data to background event object in FullCalendar

Deadly 提交于 2019-12-06 03:34:27

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

The accepted answer didnt worked for me as I cant trigger the click due to multiple issues(z-index, height). I think I found a much cleaner solution.

The solution is to use the fullcalendar clientEvents method. It will use the client side copy of the events. So no extra api call.

Both select and dayClick will gets fired when selecting a date. So choose the one that best suits your needs. I think select is a good choice as it gets fired for multiple days selection aswell if needed.

    select: function (startDate, endDate, jsEvent, view, resource) {

       //below code for passing events in bg events of fullcalender
                          var events = $('#calendar').fullCalendar('clientEvents', function (evt) {
                        //if same date as clicked date add element to events array
                          return evt.start.isSame(startDate);//must return boolean
                    });



                    console.log(events);
}

Hope this helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!