2

Actually title is telling everything. I do a ajax call, it's return a event list.Then I want put the list into fullcalendar. This operation should be for every changed selected username.

$.ajax({
    type: "POST",
    url: "get_event_list.php",
    data: "username="+user,
    success: function(ajaxCevap) {

        var obj = jQuery.parseJSON(ajaxCevap);
        var events = new Array();

        $.each(obj,function(index,value) {

            event = new Object();       
            event.title = value['title']; 
            event.start = value['start']; 
            event.end = value['end'];
            event.color = value['backgroundColor'];
            event.allDay = false;

            events.push(event);
        });

        $('#calendar').fullCalendar("removeEvents");        
        $('#calendar').fullCalendar('addEventSource', events);      
        $('#calendar').fullCalendar('refetchEvents');

    }
});

addEventSource is not working. Nothing append to fullcalendar.

Here is the container : <div id="calendar"></div>

--- EDIT ---

I get an error : Uncaught exception: TypeError: Cannot convert 'getDaySegmentContainer()' to object

3 Answers 3

2

I used a style suggested by the fullcalendar documentation: http://arshaw.com/fullcalendar/docs/event_data/Event_Source_Object/

So if you are using rails like I was, I had this in my document ready script:

eventSources: [{
    url: '/mymodel.json',
    ignoreTimezone: false
}],

Then in the model itself:

def index
#gets list

@mymodel = Mymodel.all.map { |r| {:title => r.title , :start => r.date, :color => '#66FF33', :end => r.enddate, :id => r.id} } 

 respond_to do |format|
    format.html
    format.json { render :json => @mymodel }
 end
end
3
  • How to refetch your events after username change ? This code is run at first load. Commented Sep 4, 2013 at 7:42
  • If you "logged out" or you change your username, the page should refresh itself and the events will reload accordingly.
    – kjbradley
    Commented Sep 4, 2013 at 14:33
  • If your username change stimulates a page request or refresh, it should be the same as a "first load".
    – kjbradley
    Commented Sep 4, 2013 at 15:49
0

Have a look at my answer, i faced the same issue where i was unable to map events to jquery fullcalender. Got it to work after three days of struggle.

Here's the link

Maping Events to FullCalender using JSON

0

I have worked in something like that, but using 'month' value to obtain only the events of the month selected and replace all events in the calendar

My javascript code:

  $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: ''
        },
        editable: false,
        events: function (start, end, timezone, callback) {


            var d = new Date();
            var n = d.getMonth();

            var month = n + 1; //actual month 
            try {
                //if the View is diferent of today , get the number of month from the actual view
                month = parseInt($('#calendar').fullCalendar('getDate').format("MM"));
            }catch(e){}

            $.ajax({
                url: $("#url-events").val(), //GetEventsByMonth
                dataType: 'json',
                data: {
                    //pass the parameter to get the events by month
                    month: month
                },
                success: function (result) {
                    var events = [];
                    $.each(result, function (i, item) {

                        events.push({
                            title: result[i].title,
                            start: result[i].start,// will be parsed
                            end: result[i].end // will be parsed
                        });
                    })                        
                    callback(events);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);

                }


            });
        }

    });

My Action Method:

 public ActionResult GetEventsByMonth(int month)
    {

        List<Events> list = Events.GetEvents(month);
        var rows = list.ToArray();
        return Json(rows, JsonRequestBehavior.AllowGet);
    }

You could change the 'month' parameter by 'user' and bring them all events of the respective user.

My Model:

 public class Events
{
    public string id { get; set; }
    public string title { get; set; }
    public string date { get; set; }
    public string start { get; set; }
    public string end { get; set; }
    public string url { get; set; }

    public bool allDay { get; set; }


    public static List<Events> GetEvents(int month= 0)
    {
      ...
    }


}
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.