简体   繁体   中英

Limit the number of events created per day in fullcalendar

I am working with fullcalendar. I want to limit the number of events created per day to 4 in week's view. I have seen this link but it is not of much help stackoverflow question eventLimit options only limits the events displayed but I want to stop creating events once 6 events have been created per day in week's view.

Try this.

select: function( start, end, jsEvent, view) {
    var eventCounter = 0;
    $('#calendar').fullCalendar('clientEvents', function(event) {
        if (start.format('YYYY-MM-DD') == event.start.format('YYYY-MM-DD')) {
            eventCounter++;
        }
    });
    if (eventCounter < 6) {
        // Code to create event
    }
}

This works for me locally.

Okay after digging deep and learning more about fullcalender, here is how i did it. it was very easy i must say. `

 var event_count=0;// to count the number of events starting from zero $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: '2016-01-12', editable: true, selectable: true, minTime: '09:00:00', maxTime: '18:00:00', columnFormat: 'dddd', eventLimit: true, select: function(start, end) { var eventData = { start: start, end: end }; event_count+=1;//if the control is inside this function increment eventcount if(event_count<4){ //if the counter is less than four then do this $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true $('#calendar').fullCalendar('unselect'); } }, eventClick: function(event){ $('#calendar').fullCalendar('removeEvents',event._id); event_count-=event_count;//decrement event_count when event is removed }, loading: function(bool) { $('#loading').toggle(bool); } }); $('#view_calendar').on('shown.bs.modal', function () { $("#calendar").fullCalendar('render'); }); }) 

`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM