Change cell background in fullCalendar agenda view based on start and end of a selection event

ⅰ亾dé卋堺 提交于 2019-12-04 16:13:29

For this situation you have to do little tricky hack in fullcalendar.js.

First, In agenda view there is a single full row for all days eg. Week start from 3rd Jan, 2016 to 9th Jan, 2016. And for 08:00 you will have single horizontal row () which start from 3rd Jan, 2016 to 9th Jan, 2016. Here you have to make separate div blocks and set date and time as id attribute for each days within that particular single row.

Second, On your selection bases you can apply class by getting element by id whereas id is combination of date and time.

I understand the question as 'Can i change day cel colors based on the start or end times of the events in them. If so - yup! =)

Do some logic in eventRender and look for the dom object of the day cel using it's data-date property (in this case i highlight any days that have a event before noon):

Fiddle

$(document).ready(function() {
    $('#calendar').fullCalendar({   
        ...
        eventRender: function(event, element){
                    if (event.start.hours() < 12){
                $("td [data-date='" + event.start.format("YYYY-MM-DD") + "']").addClass('highlight-red');
              }
            },
        ...
    });
});

<style>
    #calendar .fc-day.highlight-red{
        background-color: red;
    }
</style>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!