Fullcalendar: Change the color for specific days

前端 未结 8 922
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 16:31

I\'m stuck with a project I get at work. I need to change the background color of some days. It\'s a calendar where the user should see, which days are available and which n

相关标签:
8条回答
  • 2020-12-08 16:46

    To compare using the date parameter for a specific day:

    $("#calendar").fullCalendar({
        dayRender: function (date, cell) {
            if (date.isSame('2016-08-04')) {
               cell.css("background-color","red");
            }
        }
    });
    

    isSame comes from moment.js, which is used by fullcalendar: http://momentjs.com/docs/#/query/is-same/

    0 讨论(0)
  • 2020-12-08 16:48

    For the views month, basicWeek and basicDay you can change the rendering of the days by providing a dayRender function. E.g.:

    $("#calendar").fullCalendar({
        dayRender: function (date, cell) {
            cell.css("background-color", "red");
        }
    });
    

    The documentation for dayRender is available here: http://arshaw.com/fullcalendar/docs/display/dayRender/

    And here's a working example on jsfiddle: http://jsfiddle.net/kvakulo/CYnJY/4/

    0 讨论(0)
  • 2020-12-08 16:52

    For those looking to simply change the color of past dates, target .fc-past in your css and add a background-color property. E.g.,:

    .fc-past {
        background-color: silver;
    }
    
    0 讨论(0)
  • 2020-12-08 16:53
        dayRender: function(date, cell){
            if (moment().diff(date,'days') > 0){
                cell.css("background-color","silver");
            }
        },
    
    0 讨论(0)
  • 2020-12-08 16:55

    If any one want to jquery fullcalendar previous all day red(or any other) colored then this is the code.

        var $calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
    
        defaultView: 'month',
    
        dayRender: function (date, cell) {
           var check = $.fullCalendar.formatDate(date,'yyyy-MM-dd');
                        var today = $.fullCalendar.formatDate(new Date(),'yyyy-MM-dd');
                        if (check < today) {
                            cell.css("background-color", "red");
                        }
        }
    });
    

    Regin Larsen code help me achive this. Thanks Regin Larsen.

    0 讨论(0)
  • 2020-12-08 16:56

    getDate does not work I guess, use moment instead.

    inside var calendar = $('#calendar').fullCalendar({ ... }

    dayRender: function (date, cell) {
            var today = moment('2018-06-22T00:00Z');
            if (date.isSame(today, "day")) {
                cell.css("background-color", "blue");
            }
        },
    
    0 讨论(0)
提交回复
热议问题