FullCalendar load events from JSON feed to viewRender

FullCalendar v2.2.5, I want to use a JSON

script to fetch data for only the visible area of ​​the calendar, as mentioned in several other questions.

$(document).ready(function() {
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay',
            defaultAllDay: true,
        },
        lazyFetching: false,
        defaultDate: '2015-01-06',
        editable: false,
        eventLimit: 10, 
        weekMode: 'liquid',
        dayPopoverFormat: 'DD/MM/YYYY',

        //events: {
        //          url: 'instant-tools.cgi',
        //          type: 'POST',
        //          data: {
        //              events: 1,
        //              pending: 1,
        //              from: '2014-01-01',
        //              to: '2016-12-31',
        //          }
        //      },

        viewRender: function(view, element) {
            var events_slice = new Object();
            events_slice.eventSources = [
                {
                    url: 'instant-tools.cgi',
                    type: 'POST',
                    data: { events: 1, pending: 1, from: '2014-01-01', to: '2016-12-31' }
                }
            ];

            $('#calendar').fullCalendar('addEventSource', events_slice);

            //$('#calendar').fullCalendar('renderEvents');
        },

        eventClick: function(calEvent, jsEvent, view) {
            alert(calEvent.title + "n" + calEvent.start.format('DD/MM/YYYY') + " to " + calEvent.end.format('DD/MM/YYYY'));
        },
    });
});

      

The commented out definition events

works (when I use it), but it viewRender

doesn't. Before you ask viewRender

, it will fail. I see no errors in the console and no events are displayed. My script is called not . I know I have dates hardcoded right now, but I will use view.intervalStart

and view.intervalEnd

as soon as I confirm I get a similar result. While $('#calendar').fullCalendar('renderEvents');

it doesn't make any difference, switching lazyFetching

is also irrelevant. Not JS code, so I hope I'm just stupid somewhere.

+3


source to share


1 answer


in the event property you need to call the function



$(document).ready(function() {
  $('#calendar').fullCalendar({
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,basicWeek,basicDay',
      defaultAllDay: true,
    },
    lazyFetching: false,
    defaultDate: '$today',
    editable: false,
    eventLimit: 10,
    weekMode: 'liquid',
    dayPopoverFormat: 'DD/MM/YYYY',

    events: function(start, end, timezone, callback) {
      $.ajax({
        url: 'instant-tools.cgi',
        data: {
          events: 1,
          pending: 1,
          from: '2014-01-01',
          to: '2016-12-31',
        },
        success: function(doc) {
          var obj = jQuery.parseJSON(doc);
          var events = [];
          $.each(obj, function(index, value) {

            events.push({
              id: value['id'],
              //all data
            });
            //console.log(value)
          });
          callback(events);
        },
        error: function(e, x, y) {
          console.log(e);
          console.log(x);
          console.log(y);
        }
      });
    },

    eventClick: function(calEvent, jsEvent, view) {
      alert(calEvent.title + "n" + calEvent.start.format('DD/MM/YYYY') + " to " + calEvent.end.format('DD/MM/YYYY'));
    },
  });
});

      

+4


source







All Articles