0

Hi I am trying to implement FullCalendar.js with Asp.Net MVC. I am abl to show empty calendar but my events are not getting loaded in the Calendar.

 $.ajax({
                type: 'Get',
                url: "/Matter/GetMatterEventsSummary",
                data: data,

                datatype: "Json",

                contentType: "application/json",
                success: function (doc) {
                    debugger;
                    $('#calendar').fullCalendar();
                    var events = [];
                    $(doc).find('[object Object],[object Object]').each(function () {
                        debugger;
                    events.push({

                            title: $(this).attr('title'),
                            start: $(this).attr('start') // will be parsed
                        });
                   // });
                    $('#calendar').fullCalendar('refetchEvents');
                  //  callback(events);
                }

            });

it comes to success method and it has two events in it . but dont know why theseevents are not loaded into FullCalendar and also after this Calendar is not comingg automatically. I guess it is not going in events.push. When I do hover on doc it shows "[object Object],[object Object]" and in this it has two records on [0] and [1].

Please help me in this.

1 Answer 1

1

Try using

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

after your events have been pulled.

Also, make sure to use the code from the official documentation properly. Try the following (untested):

$('#calendar').fullCalendar({
  events: function(start, end, timezone, callback) {
    $.ajax({
        type: 'Get',
        url: "/Matter/GetMatterEventsSummary",
        data: data,
        datatype: "Json",
        contentType: "application/json",,
        success: function(doc) {
            var events = [];
            $(doc).find('event').each(function() {
                events.push({
                    title: $(this).attr('title'),
                    start: $(this).attr('start') // will be parsed
                });
            });
            callback(events);
        }
    });
  }
});

If you now want to refetch your events, call :

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

where necessary.

EDIT: Since your are actually pulling data from a JSON feed, the following code may even be enough:

$('#calendar').fullCalendar({
    events: '/Matter/GetMatterEventsSummary'
});

Check the documentation here:

EDIT2:

To dynamically modify the request you send to the backend (depending on a dropdown or something else), may be achieved as follows:

 var myValue = 10;

 $('#calendar').fullCalendar({
    events: '/Matter/GetMatterEventsSummary',
    data: function() { // a function that returns an object
        return {
            dynamic_value: myValue
        };
    }
});
6
  • Thanks, I am able to get the events on the Calendar with the edited answer but still facing the issue as when the page is first loading I am getting nothing and if I click on the arrow I will get the data. Commented Feb 15, 2016 at 6:01
  • Also I want to show the current month activities in the Calendar, do I need to pass dates in this and if yes then how will month will change on click of arrow. Commented Feb 15, 2016 at 6:11
  • Regarding your first comment, have you tried calling 'refetchEvents' (after you calendar has been loaded), as I described above? Regarding your second comment, I'm not exactly sure if I understand you correctly. As written in the documentation (link in my answer), fullcalendar automatically send start and end date like (.../Matter/GetMatterEventsSummary/start=2013-12-01&end=2014-01-12) to the backend. Every time you click on the arrow, an new request will be sent to the backend with adjusted start/end dates. In the backend you have to read out those values and return the appropriate events.
    – Kito
    Commented Feb 15, 2016 at 14:30
  • Thanks for the reply, I have tried the 'refetchEvents' (after the calendar has been loaded) but didn't work for me. Commented Feb 16, 2016 at 3:56
  • Can you also tell me how can I change the data of Calendar on dropdown change event, I am able to get the data according to changed value of dropdown but how can I set this value on the success event. Commented Feb 17, 2016 at 10:14

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