rerenderEvents / refetchEvents problem

后端 未结 5 1946
情歌与酒
情歌与酒 2020-12-31 16:01

I am not sure if I am using this correctly so my problem may be my mis-understanding rather than a bug or larger problem.

I have a fullcalendar that gets initiated f

相关标签:
5条回答
  • 2020-12-31 16:23
    newEvents = [...]
    
     $('#calendar').fullCalendar('removeEvents');
     $('#calendar').fullCalendar( 'addEventSource', newEvents);
    

    no need to 'rerenderEvents' and works like a charm!

    0 讨论(0)
  • 2020-12-31 16:24

    In pseudo, remove old events, add a new event source, then refetch events (from the only source, which is now the new source):

    • This is untested, but try removing the old events:

    $('#calendar').fullCalendar('removeEvents')

    • Then add the new event source (According the the documentation, this should fetch the events and display them on the screen, but it appears not to work, so follow it with the next command which is like a refresh):

    $('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians)


    EDIT: Instead of:

    Then refetch and render the new events:

    $('#calendar').fullCalendar( 'refetchEvents' )

    OR:

    • Use the following, as you mention, running addEventSource fetches the new events, so this should render the newly fetched events:

    $('#calendar').fullCalendar('rerenderEvents')

    0 讨论(0)
  • 2020-12-31 16:28
    $('#calendar').fullCalendar('removeEvents');
    $('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians);
    $('#calendar').fullCalendar('rerenderEvents');
    

    The above solution works, but every time you run it, it add an eventSource.

    So when you need to run $('#calendar').fullCalendar('refetchEvents'); you will get events from all sources, so many dublicate events and events from all previous sources.

    The solution that works for me good is:

    $('#calendar').fullCalendar('removeEventSource', 'JsonResponse.ashx?technicans=' + technicians);
    technicians = new_technicians_value;
    $('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians);
    

    And there is no need for "rerenderEvents" or "refetchEvents".

    After "addEventSource" events will be immediately fetched from the new source.

    After that "refetchEvents" will work as supposed to when needed.

    0 讨论(0)
  • 2020-12-31 16:33

    with fulcalendar 4.x I'm using something like this:

    initialize calendar as usual:

     var calendar = $('#calendar').fullCalendar({
           ...
            events: "JsonResponse.ashx?technicians=" + technicians,
           ... 
     });
    

    and then when you need to redraw events:

    var eventSources = calendar.getEventSources();
    for(var i in eventSources)
    {
        var evres=eventSources[i];
        evres.refetch();
    }
    calendar.render();
    
    0 讨论(0)
  • 2020-12-31 16:41

    Thanks for the help!

    Here is what worked based on Scoobler's suggestions the steps that work are (1) removeEvents. (2) addEventSource, (3) rerenderEvents.

    $('#calendar').fullCalendar('removeEvents');
    $('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians);
    $('#calendar').fullCalendar('rerenderEvents');
    
    0 讨论(0)
提交回复
热议问题