Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update an event in fullCalendar?

I want to update my json in fullcalendar, Here is what I am exactly trying to do. I have a JSON string which I am directly trying to feed in to the event objects in the full calendar.

-->

var JSON[
    {
        "id": "1", // Optional
        "title": "Demo event", // Required
        "start": "2013-08-28 10:20:00", // Required
        "end": "2013-08-28 11:00:00", // Optional
        "allDay": false, // Optional
        "url": "http://google.com", // Optional, will not open because of browser-iframe security issues
        "className": "test-class", // Optional
        "editable": true, // Optional
        "color": "yellow", // Optional
        "borderColor": "red", // Optional
        "backgroundColor": "yellow", // Optional
        "textColor": "green" // Optional
    },
    {
        "id": "2", // Optional
        "title": "Demo event 2", // Required
        "start": "2013-08-27 10:20:00", // Required
        "end": "2013-08-27 11:00:00", // Optional
        "allDay": false, // Optional
        "url": "http://google.com", // Optional, will not open because of browser-iframe security issues
        "className": "test-class", // Optional
        "editable": true, // Optional
        "color": "yellow", // Optional
        "borderColor": "red", // Optional
        "backgroundColor": "yellow", // Optional
        "textColor": "green" // Optional
    }
];

,

Then I want to modify the JSON on some drop down event (not shown in the fiddle) to a new string and try to get the new event on the calendar.

The fullCalendar does not take effect.

http://jsfiddle.net/pratik24/u8Ksw/28/

Thanks for the help. appreciate it.

like image 532
patz Avatar asked Aug 28 '13 20:08

patz


People also ask

How do you use events in fullCalendar?

Here is an example of how to specify an array of events: var calendar = new Calendar(calendarEl, { events: [ { title : 'event1', start : '2010-01-01' }, { title : 'event2', start : '2010-01-05', end : '2010-01-07' }, { title : 'event3', start : '2010-01-09T12:30:00', allDay : false // will make the time show } ] });

How do I change the date on fullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

How do I change the color of an event in fullCalendar?

You can change the color of all events on the calendar like so: var calendar = new Calendar(calendarEl, { events: [ // my event data ], eventColor: '#378006' }); You can use any of the CSS color formats such #f00 , #ff0000 , rgb(255,0,0) , or red .


1 Answers

You aren't calling the correct fullCalendar method to render the new events.

This will not work because it is only meant to render the events the first time around:

   $("#demo-calendar").fullCalendar('renderEvents', JSON);

Instead you need to remove the events on the calendar and refresh them:

   $("#demo-calendar").fullCalendar('removeEvents'); 
   $("#demo-calendar").fullCalendar('addEventSource', JSON); 

Check the Fiddle: http://jsfiddle.net/shaunp/u8Ksw/29/

NOTE that there is a fullCalendar method called refetchEvents, but that it does NOT work on an array of events such as what you have created, so you must manually take the events off and re-add the event source again.

like image 54
Shaun Avatar answered Oct 12 '22 23:10

Shaun