Search code examples
c#asp.netsql-serverfullcalendargeneric-handler

Limit the data access based on start and end date for full calendar


Beginner for New Calendar I want to retrieve the events from a database for the full Calendar but I want to limit or restrict the data for a specific date range that is appearing on the screen

for Retrieving events I need to pass a start date and end Date that has been selected on the screen to a generic handler i.e. NewJosn.ashx

Sample code I'm using is:

var calendar = $('#calendar').fullCalendar({
    theme: true,
    height: calHeight,
    allDaySlot: false,
    disableDragging: false,
    defaultView: 'agendaWeek',
    slotEventOverlap: false,
    slotMinutes: varTimeSlot,
    firstHour: startTimeNew,
    firstDay: varFirstDay,
    header: {
        left: '',
        center: 'prev,today,title,next',
        right: 'resourceDay,agendaWeek,month' //resourceDay
    },
    timeFormat: 'h(:mm)tt{ - h(:mm)}tt',
    axisFormat: 'h(:mm)tt',
    editable: true,
    events: 'NewJSON.ashx',
    eventDrop: eventDropped,
    eventClick: function (calEvent, jsEvent, view) {
    },
    viewDisplay: function (view) {   
    },
    eventMouseover: function (event, jsEvent, view) {
            $(jsEvent.target).attr('title', event.title);
    },
    eventMouseout: function (event, jsEvent, view) {
    },
    dayClick: function (date, allDay, jsEvent, view) {

    },
    eventAfterRender: function (event, element, view) {
    },
    resources: [
                {
                    name: 'Resource 1',
                    id: '1'
                },
                {
                    name: 'Resource 2',
                    id: '2'
                },
                {
                    name: 'Resource 3',
                    id: '3'
                },
                {
                    name: 'Resource 4',
                    id: '4'
                }
    ]
});

Solution

  • You shouldn't need to do anything really. If you're defining your events as a JSON feed, which it looks like you are, then see the docs here: http://fullcalendar.io/docs/event_data/events_json_feed/

    "FullCalendar will visit the URL whenever it needs new event data. This happens when the user clicks prev/next or changes views. FullCalendar will determine the date-range it needs events for and will pass that information along in GET parameters."

    So all your need to do is ensure the method in your server-side handler can receive the start and end date parameters and limit the data it returns appropriately.