FullCalendar switch between weekends and no weekends

后端 未结 7 1471
天命终不由人
天命终不由人 2021-01-14 15:48

I was wondering if there was a way in Arshaw\'s FullCalendar to: 1- Change the calendar from showing weekends to not show weekends and vice versa. 2- To dynamically change t

7条回答
  •  情书的邮戳
    2021-01-14 16:39

    Update for 2017: FullCalendar added a weekend setter in 2.9.0 (7-10-2016), so no calendar destroy or custom view manipulation is necessary anymore.

    Here's how I implemented a weekend toggle in my production app using FullCalendar 3.1.0:

    var calendarOptions = {
      ...
      customButtons: {
        toggleWeekends: {
          text: 'Show Weekends',
          click: function() {
            toggleWeekends();
          },
        },
      },
      ...
      header: {
        left: 'today toggleWeekends',
        ...
      },
      weekends: false,
    }
    
    function toggleWeekends() {
      var weekends = $('#calendar').fullCalendar('option', 'weekends');
      var text = 'Show Weekends';
    
      if (weekends == false) {
        text = 'Hide Weekends';
      }
    
      $('#calendar').fullCalendar('option', {
        customButtons: {
          toggleWeekends: {
            text: text,
            click: function() {
              toggleWeekends();
            },
          },
        },
        weekends: !weekends,
      });
    }
    

提交回复
热议问题