Fullcalendar limit the display of available months?

前端 未结 9 1649
伪装坚强ぢ
伪装坚强ぢ 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:45

    This is based on tauren's answer, but includes the necessary date math and fullcalendar selectors to pull it off (this code uses a range of 12 months):

    jQuery('#edit-calendar').fullCalendar({
        viewDisplay   : function(view) {
          var now = new Date(); 
          var end = new Date();
          end.setMonth(now.getMonth() + 11); //Adjust as needed
    
          var cal_date_string = view.start.getMonth()+'/'+view.start.getFullYear();
          var cur_date_string = now.getMonth()+'/'+now.getFullYear();
          var end_date_string = end.getMonth()+'/'+end.getFullYear();
    
          if(cal_date_string == cur_date_string) { jQuery('.fc-button-prev').addClass("fc-state-disabled"); }
          else { jQuery('.fc-button-prev').removeClass("fc-state-disabled"); }
    
          if(end_date_string == cal_date_string) { jQuery('.fc-button-next').addClass("fc-state-disabled"); }
          else { jQuery('.fc-button-next').removeClass("fc-state-disabled"); }
        }
    });
    

提交回复
热议问题