How to select multiple date ranges from Fullcalendar?

后端 未结 1 1336
Happy的楠姐
Happy的楠姐 2020-12-31 18:45

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

1条回答
  •  囚心锁ツ
    2020-12-31 19:15

    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.

    0 讨论(0)
提交回复
热议问题