Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select multiple date ranges from Fullcalendar?

I am trying to make a calendar feature in which a user can block off multiple date ranges by just selecting the start and end dates. I was thinking of using FullCalendar but I am not sure how to proceed with this.

I did see some examples of how to block some dates from being selected by adding my check on dayClick but these do not deal with date ranges. I would appreciate any help, I am not really looking for an entire source but some suggestions on how to go about this.

like image 397
Ayrton Senna Avatar asked Mar 21 '15 10:03

Ayrton Senna


People also ask

How do I select multiple dates in FullCalendar?

Detect when the user clicks on dates or times. Give the user the ability to select multiple dates or time slots with their mouse or touch device. Allows a user to highlight multiple days or timeslots by clicking and dragging.

How do I get the date from FullCalendar?

Calendar::getDate Returns a Date for the current date of the calendar. For month view, it will always be some time between the first and last day of the month.

How do I change the date on FullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

What is FullCalendar eventRender?

eventRender is a great way to attach effects to event elements, such as a Tooltip. js tooltip effect: var calendar = new Calendar(calendarEl, { events: [ { title: 'My Event', start: '2010-01-01', description: 'This is a cool event' } // more events here ], eventRender: function(info) { var tooltip = new Tooltip(info.


1 Answers

This is a multi-part problem. Here's the basic idea.

  • Allow the user to make a click+drag selection with selectable: true
  • In the select callback, add a background event with addEventSource.
  • When adding the event, give it a custom property: block: true.
  • Use a custom function for selectOverlap that returns false if event.block.

Something like this JSFiddle.

selectable: true,
select: function (start, end, jsEvent, view) {
    $("#calendar").fullCalendar('addEventSource', [{
        start: start,
        end: end,
        rendering: 'background',
        block: true,
    }, ]);
    $("#calendar").fullCalendar("unselect");
},
selectOverlap: function(event) {
    return ! event.block;
}

Background events are optional, but this is usually desired (visually).

If dragging and dropping already created events is desired, you can use the selectOverlap function in eventOverlap as well.

like image 98
DanielST Avatar answered Sep 19 '22 03:09

DanielST