How to call events on clicking prev and next button?

后端 未结 11 1537
天涯浪人
天涯浪人 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 07:59

    You couldsimply attach an event to the button:

    $('.fc-button-prev span').click(function(){
       alert('prev is clicked, do something');
    });
    
    $('.fc-button-next span').click(function(){
       alert('nextis clicked, do something');
    });
    
    0 讨论(0)
  • 2020-12-24 07:59

    Version 3 the answer is to use:

    viewRender: function (event, element, view){
    // you code here
    }
    

    Version 4: https://fullcalendar.io/docs/v4/datesRender

    datesRender: function (){
        // you code here
        }
    

    https://fullcalendar.io/docs/v4/upgrading-from-v3

    "viewRender Renamed to datesRender. Parameters have changed."


    Version 5 Use :

    datesSet: function (){
        // you code here
        }
    

    "datesRender changed to: datesSet - renamed from datesRender. Called after a view's dates are initialized or when they change." https://fullcalendar.io/docs/upgrading-from-v4

    0 讨论(0)
  • 2020-12-24 08:04

    The best way is:

    viewRender: function(view, element) {
      var b = $('#calendar').fullCalendar('getDate');
      alert(b.format('L'));
    },
    
    0 讨论(0)
  • 2020-12-24 08:06
    $('.fc-button-next span').click(function(){
    
       //do your work 
    
    });
    
    
    $('.fc-button-prev span').click(function(){
    
       //do your work 
    
    });
    
    0 讨论(0)
  • 2020-12-24 08:11

    During declaration of Calendar in events you can write the event's callback function:

    $('#calender').fullCalendar({
    
    events:  function (start, end, timezone, callback) {
                        callback(eventsarray);
                    }
    });
    

    //eventsarray - This is a collection of data of the calendar. You can also call month wise function in this by passing first and last date of selected / current month and handle prev and next event.

    0 讨论(0)
  • 2020-12-24 08:14

    When the next and previous buttons are clicked, the events function is called. Here is an example to load data for the current year:

    $(document).ready(function() {
      loadCal();
    });
    
    function loadCal() {
    
      var current_url = '';
      var new_url = '';
    
      $('#calendar').fullCalendar({
    
        // other options here...
    
        events: function(start, end, callback) {
    
          var year = end.getFullYear();
    
          new_url = '/api/user/events/list/' + id + '/year/' + year;
    
          if (new_url != current_url) {
    
            $.ajax({
              url: new_url,
              dataType: 'json',
              type: 'POST',
              success: function(response) {
    
                current_url = new_url;
                user_events = response;
    
                callback(response);
              }
            })
          } else {
            callback(user_events);
          }
        }
      })
    }
    

    When you retrieve the results in a query, make sure you include at least the last 10 days from the previous year and the first 10 days from the next year.

    0 讨论(0)
提交回复
热议问题