search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Calendar events not updating

Asked by Richard
8 years ago.

Hi,

I'm making use of the following code to update the calendar control, but the events aren't being updated? Not sure why...

// ... loop for each time entry
            // construct a new day pilot event object
            var event = new DayPilot.Event({
                start: new DayPilot.Date(timeEntry.TimeDate).addHours(appConfig.defaultWorkdayStart + cachedTime),
                end: new DayPilot.Date(timeEntry.TimeDate)
                    .addHours(appConfig.defaultWorkdayStart + timeEntry.TimeHours + cachedTime),
                id: timeEntry.TimeId,
                text: timeEntry.TimeDescription,
                tags: {
                    meta: timeEntry,
                    color: timeEntry.color
                },
                resource: timeEntry.ClientId,
                backColor: getBackColorByStatus(timeEntry)
            });

            // check whether the calendar control already contains the specific event
            if (vm.calendar.events.find(event.id()) == undefined) {
                // if not, add
                vm.calendar.events.add(event);
            } else {
                // if so, update
                vm.calendar.events.update(event);
            }
// ...loop end

 vm.calendar.update();

Could you please assist?
Many thanks in advance!

Answer posted by Dan Letecky [DayPilot]
8 years ago.

1. If you have a complete data set that you want to display (i.e. you don't plan to apply any "diff" to the event set) the recommended way is to assign the array directly to .events.list:

vm.calendar.events.list = [
  { start: ..., end: .... }
  // ...
];
vm.calendar.update();

This is the fastest way to update events.

2. You can also add them one-by-one using dp.events.add(). In this case it's not necessary to call dp.update() when the loop is complete.

Note that the changes made using dp.events.add() and dp.events.update() are merged and they are displayed when you are done (i.e. the calendar is refreshed only once). The update is postponed using setTimeout() - it's executed asynchronously.

3. If the events still don't update you should check the event data - a common problem is that the resource ID doesn't match.

You can also check if the events are correctly added to the dp.events.list array (print it to console) when using method #2.

Let me know if it didn't help.

Comment posted by Richard
8 years ago.

For any one else struggling with this issue, I came right by following the first point mentioned by Dan.

Thanks Dan!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.