Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

ui-calendar display not updating on change of Event Source Object date - dayClick #219

Open
gigmaps opened this issue Jan 28, 2015 · 11 comments

Comments

@gigmaps
Copy link

gigmaps commented Jan 28, 2015

When updating calendar using dayClick function to an Event Source Object
the calendar isn't updating - see this SO question http://stackoverflow.com/questions/28100852

This fiddle is with the latest versions and DOES NOT work as expected:

Problem:

  • the Event Source Object IS being updated, as you can see from the output below the calendar
  • to update the calendar display, switch between tabs (which are set using an ng-if directive).

This fiddle is with older versions and (for this issue) DOES work as expected

(however it's got an $interpolate issue and is missing a bunch of other functionality relating to colours & background events etc)

The only difference between the two fiddles is the fullcalendar and ui-calendar source code.

Does anyone know of a fix or workaround to have calendar display updated on update of an Event Source Object ?

@gigmaps
Copy link
Author

gigmaps commented Feb 5, 2015

I've tried the following :

I've also tried the solution proposed here (didn't work):

and the one proposed here (although 'stick = true' is kinda the opposite of what i want on the event really) - didn't work:

@papasax
Copy link

papasax commented Feb 11, 2015

I think i had the same problem.
$('#calendar').fullCalendar('refetchEvents') fixed it for me. But there is a bug in the watcher.

@dmexs
Copy link

dmexs commented Feb 22, 2015

I solved my trouble by splicing the array down to nothing and then pushing new values to the same array. The trouble seems to be the calendar using the old memory reference to the initial array. If you replace the array for whatever reason the calendar doesn't update it's memory reference.

http://stackoverflow.com/a/28663610/271868

@joshkurz
Copy link
Contributor

joshkurz commented May 9, 2015

yeah something is still wrong here. Looked into it for a bit, but could not figure it out immediately. Thanks for reporting this @gigmaps, will try to figure it out. if anyone wants to try this one out, that would be great. Thanks. :)

@joshkurz
Copy link
Contributor

joshkurz commented May 9, 2015

@gigmaps I think this solves the issue, we just need a PR #167

@laurenmacam
Copy link

thanks @dmexs it worked for me!

@MariusHerget
Copy link

My workaround is working fine but may have problems, if you load lots of events.
(newEvents is a filtered version of the original EventSources.)

 angular.element('.calendar').fullCalendar( 'removeEventSources' );
 angular.element('.calendar').fullCalendar( 'removeEvents' );

 for (var sour in newEvents) {
        angular.element('.calendar').fullCalendar( 'addEventSource', newEvents[sour] );
 } 

@wilchemh
Copy link

wilchemh commented Sep 17, 2017

I too had this issue. I traced it down to the following function in dependent js fullCalendar js

The fullCalendar function is looking for the value of id in the event object, which does not exist.
With the below change the angular watcher from calendar.js correctly removes and updates items from a $scope Events Array in the calendar.

The reason the remove all work around resolves this issue is because both remove all and add are not dependent upon the legacy filter function below..

function filterLegacyEventInstances(legacyEventInstances, legacyQuery) {

if (legacyQuery == null) {
    return legacyEventInstances;
}
else if ($.isFunction(legacyQuery)) {
    return legacyEventInstances.filter(legacyQuery);
}
else { // an event ID
    legacyQuery += ''; // normalize to string
    return legacyEventInstances.filter(function(legacyEventInstance) {
        // soft comparison because id not be normalized to string
        // console.log(legacyEventInstance.id  + " == " +  legacyQuery);      
        // console.log(legacyEventInstance._id  + " == " +  legacyQuery);
        // updated Below line changed id --> _id as that is what ui.calendar passes as id
        return legacyEventInstance._id == legacyQuery;
    });
}

}

@gabrielgoiscastor
Copy link

@dmexs thank you. I'm searching for a solution for this problem for the past 4 hours, finally some insights on it!

@lironbar
Copy link

lironbar commented Jan 7, 2019

For anyone who runs into it that might help:
HTML Example:

<div flex id="calendar" ui-calendar="$ctrl.calendarOptions" ng-model="$ctrl.eventSources" calendar="exampleCalendar"></div>

That what needs to be done:

uiCalendarConfig.calendars.exampleCalendar.fullCalendar('removeEventSources'); uiCalendarConfig.calendars.exampleCalendar.fullCalendar('removeEvents'); ctrl.eventSources.push(ctrl.events);

*Dont forget to inject uiCalendarConfig to the controller

Worked for me :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

11 participants