How to call events on clicking prev and next button?

后端 未结 11 1649
天涯浪人
天涯浪人 2020-12-24 07:26

In jQuery fullcalendar we have previous and next buttons. How can we call some events on click of these buttons?

11条回答
  •  佛祖请我去吃肉
    2020-12-24 08:22

    I see there are other working answers, but IMHO the simplest and more correct - at least using FullCalendar v.4 - is to intercept prev and next is to deal them in the same way of custom buttons.

    Here my setup (using toastr just for demo purposes)

    document.addEventListener('DOMContentLoaded', function() {
      var calendarEl = document.getElementById('calendar');
    
      var calendar = new FullCalendar.Calendar(calendarEl, {
        plugins: [ 'dayGrid', 'timeGrid' ],
        header: {
          left: 'dayGridMonth,timeGridWeek,timeGridDay',
          center: 'title',
          right: 'prev,next'
        },
        footer: {
          left: '',
          center: '',
          right: 'prev,next'
        },
        customButtons: {
          prev: {
            text: 'Prev',
            click: function() {
                        // so something before
                        toastr.warning("PREV button is going to be executed")
                        // do the original command
                        calendar.prev();
                        // do something after
                        toastr.warning("PREV button executed")
            }
          },
          next: {
            text: 'Next',
            click: function() {
                        // so something before
                        toastr.success("NEXT button is going to be executed")
                        // do the original command
                        calendar.next();
                        // do something after
                        toastr.success("NEXT button executed")
            }
          },
        }
      });
    
      calendar.render();
    });
    

    See a Codepen here

提交回复
热议问题