Fullcalendar limit the display of available months?

前端 未结 9 1639
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 04:11

I would like to find out how can I limit the fullcalendar to show a three months period and deselectable for the rest of the months like within a datepicker?

E.g. T

9条回答
  •  暖寄归人
    2020-12-11 04:28

    I liked lewsid's answer a lot but it has some issues. First of all, the view.start is a Moment, not a date, so getMonth() does not exist. Secondly, a View's start is just the first visible day in that month, meaning that date can be from the previous month. To circumvent this, use its intervalStart property.

    Here is my implementation to get the calendar to list the current year.

    viewRender: function(view, element) {
        var now = new Date(new Date().getFullYear(), 0, 1);
        var end = new Date(new Date().getFullYear(), 11, 31);
    
        var calDateString = view.intervalStart.month()+'/'+view.intervalStart.year();
        var curDateString = now.getMonth()+'/'+now.getFullYear();
        var endDateString = end.getMonth()+'/'+end.getFullYear();
    
        if (calDateString === curDateString) {
            jQuery('.fc-prev-button').addClass("fc-state-disabled");
        } else {
            jQuery('.fc-prev-button').removeClass("fc-state-disabled");
        }
    
        if (endDateString === calDateString) {
            jQuery('.fc-next-button').addClass("fc-state-disabled");
        } else {
            jQuery('.fc-next-button').removeClass("fc-state-disabled");
        }
    }
    

提交回复
热议问题