skip to Main Content

I’m using Full Calendar and rrule plug in .net 8 core project. I’m trying to add the exdate to recurring events. Here is my code

events: function (fetchInfo, successCallback, failureCallback) {
$.ajax({
    url: "@Url.Action("GetCalendarEvents", "CalendarEvents")",
    method: 'GET',
    dataType: 'json',
    success: function (response) {
        var events = [];

        $.each(response, function () {
            var e = "'2024-11-05T13:30:00','2024-11-07T13:30:00'";
            var temp = '';
            if (this.dtstart !== null) {
                temp = this.dtstart.replace(/-/g, '');
                temp = temp.replace(/:/g, '');
                var r = 'DTSTART:' + temp + 'nRRULE:' + this.rrule;
            }
            events.push({
                title: this.title,
                start: this.event_start,
                end: this.event_end,
                backgroundColor: this.color,
                borderColor: this.color,
                textColor: '#ffffff',
                rrule: r,
                extendedProps: {
                    description: this.description,
                    start: this.start,
                    end: this.end,
                    color: this.color,
                    start_time: this.start_time,
                    end_time: this.end_time,
                    recurring: this.recurring,
                    id: this.id
                }
                //exdate: [e]
                //exdate: ['2024-11-05T13:30:00', '2024-11-07T13:30:00']
            });
        });
        successCallback(events);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        console.log('Error: ' + textStatus);
        //failureCallback();
    }
});
}

If I pass exdate: [‘2024-11-05T13:30:00’, ‘2024-11-07T13:30:00’], all works well. but if I pass exdate as a variable like this

var e = "'2024-11-05T13:30:00','2024-11-07T13:30:00'";
exdate: [e]

I get TypeError: Cannot read properties of null (reading ‘timeZoneOffset’) error. Any idea what mistake I’m making?

The reason I’m using variable is because the exdates will come from an ajax call to database.

2

Answers


  1. Chosen as BEST ANSWER

    After trying different things for one and half day, I finally got it working. I'm posting this here so it saves someone sometime. In my database, the exdates are stored in a table having nvarchar(MAX) column like this 2024-11-05T13:30:00,2024-11-07T13:30:00. No single/double quotes or brackets. Then ajax call returns data.

    let g = new Array();
    if (this.exdate != null) {      
        var c = this.exdate.split(',');                                    
        for (i = 0; i < c.length; i++) {
            g.push(c[i]);
        }       
    }
    
    events.push({
    title: this.title,
    start: this.event_start,
    end: this.event_end,
    rrule: r,
    extendedProps: {
        description: this.description,
        recurring: this.recurring,
        id: this.id
    },
    exdate: g 
    });
    

  2. I believe the issue occurs because exdate needs to be an array of date strings without the additional quotes you put around them. Var e has double quotes around the variable and single quotes around each date. Is it possible for you to create variable like this: var e = [‘2024-11-05T13:30:00’, ‘2024-11-07T13:30:00’]; ?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search