Fullcalendar, Events filer sometimes is not working

On page I have fullcalendar, variable which determines how to display now (all events or events with filter), button for changing variable value and function which applies filter.

Variable (true - show all events, false - with filter):

 var isShownWithCancelEvents = true;

Button and it's click function:

$('.fc-header-left').append('<span class="fc-button fc-button-show-with-canceled-events fc-state-default"><span class="fc-button-inner"><span id="show_without_canceled_events" class="fc-button-content">Show with filter</span><span class="fc-button-effect"><span></span></span></span>');
$(".fc-button-show-with-canceled-events").click(function() {
    isShownWithCancelEvents = !isShownWithCancelEvents;
    prepareEvents();                               
});

Function prepareEvents():

function prepareEvents(){
    if (isShownWithCancelEvents) {
        $('#calendar').fullCalendar('refetchEvents');
        $(".fc-button-show-with-canceled-events .fc-button-content ").text("Show with filter");
    }
    else {
        $('#calendar').fullCalendar ( 'removeEvents', filter );
        $(".fc-button-show-with-canceled-events .fc-button-content ").text("Show all events");
   }
}     

Filter function:

function filter(event) {
    return (event.ec_e_id !== null);
} 

Also in fullcalendar I use option:

viewDisplay: function(view) {
    prepareEvents(); 
},

Button is working, problem is with fullcalendar option.

  • Default view on page is agendaWeek. I open page and click button, variable's value changes to false, filter applies. It's OK. Then I click button "Month" and view changes to month. And I see all events. Then I click button "Week" and view changes to agendaWeek - events are filtered. I click button "Month" again - on this view events are filtered too. So, the problem is when first time changing view to another.
  • I open page and click button, variable's value changes to false, filter applies. It's OK. Then I navigate left or right (next or previous week), and I see all events. Then I return back, where events were filtered and see all events there.
  • If I add alert into fullcalendar option

    viewDisplay: function(view) {
        alert("something");
        prepareEvents(); 
    },
    

    everything is OK, and filter works every time.

    链接地址: http://www.djcxy.com/p/81248.html

    上一篇: 通过几个月,几周或几天的时间过快导致错误

    下一篇: Fullcalendar,事件文件管理器有时不起作用