Pregunta

Please any one help me to find what is going wrong in code. I used fullcalendar.js for calendar event.

I want to show the events in calendar. below is my code.

    $(document).ready(function() {

        $(window).resize(function() {
            $('#calendar').fullCalendar('option', 'height', get_calendar_height());
        });

        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
        var nevent = [];
        
        nevent = document.getElementById('<%=hdnevent.ClientID%>').value;
        
       
       // alert(nevent);
        var calendar = $('#calendar').fullCalendar({
            theme: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay',
                width: get_calendar_width
            },
            width: get_calendar_width,
            height: 480,
            selectable: true,
            selectHelper: true,
            slotMinutes: 15,
            allDayDefault: false,

            //  events: 'JsonResponse.ashx',
            events: nevent
     });

    });

nevent value is:

[{ id: '2302', title: 'XXX', start: '4/4/2014 12:00:00 AM', end: '4/4/2014 12:00:00 AM', allDay: true, url: 'xxx'}]

but it is not displayed in calendar. if i gave directly assign the value then it displaying the event.

Example:

events: [
    { 
        id: '2302', 
        title: 'XXX', 
        start: '4/4/2014 12:00:00 AM', 
        end: '4/4/2014 12:00:00 AM', 
        allDay: true, 
        url: 'xxx'
    }
]

pls kindly help me to rectify my error.

¿Fue útil?

Solución

Calendar needs to be told to update after a data change. Try:

$("#calendar").fullCalendar('removeEvents');
$("#calendar").fullCalendar('addEventSource', nevent);
$("#calendar").fullCalendar('rerenderEvents');

when nevent is ready.

EDIT:

Accept the input as JSON object not a string:

nevent = $.parseJSON(document.getElementById('<%=hdnevent.ClientID%>').value);

Note that the JSON must be in correct format with quotes like:

[{ "id": "2302", "title": "XXX", "start": "4/4/2014 12:00:00 AM", "end": "4/4/2014 12:00:00 AM", "allDay": true, "url": "xxx"}]

Otros consejos

in nevent value, start (and end) according to documentation should be: "you may specify a string in IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST"), a string in ISO8601 format (ex: "2009-11-05T13:15:30Z") or a UNIX timestamp"

so you have to convert your dates.

I have tried this way in my calendar application.It seems your date format is wrong.It should be

[{ id: '2302', start: new Date(2014, 1, 3, 12, 0), end: new Date(2014, 4, 4, 12, 0) ,allDay: true, url: 'xxx'}]

Hope this helps.

For me some events where not showing at all because i had timezone param defined. Still not sure why, but they appeared when i removed this param.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top