添加/删除eventSources FullCalendar

时间:2014-11-06 03:53:25

标签: fullcalendar

我希望能够根据添加和删除eventSource来过滤事件。我无法找到这样做的好例子。

.fullCalendar( 'addEventSource', source )
.fullCalendar( 'removeEventSource', source )

我希望有一些复选框来切换这些功能的执行。我似乎无法使功能正常工作。

$( "#target" ).click(function() { 
  $('#calendar').fullCalendar( 'removeEventSource', 'Event1' );
});

这是我的完整代码:

    $('#calendar').fullCalendar({
      header: {
    left: 'title',
    center: 'prev,next',
    right: 'month,agendaWeek,agendaDay,today'
},
       eventLimit: {
    'agenda': 4, // adjust to 6 only for agendaWeek/agendaDay
    'default': true // give the default value to other views
        },
          eventSources: [
            {
               title: 'Event1',
                url: "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic"
            },

            {

                url: 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'
            },
        {
        url: "https://www.google.com/calendar/feeds/ht3jlfaac5lfd6263ulfh4tql8%40group.calendar.google.com/public/basic"
            }
        ],

        eventClick: function(event) {
            // opens events in a popup window
            window.open(event.url, 'gcalevent', 'width=700,height=600');
            return false;
        },

        loading: function(bool) {
            if (bool) {
                $('#loading').show();
            }else{
                $('#loading').hide();
            }
        }

    });

2 个答案:

答案 0 :(得分:2)

加载FullCalendar:使用以下给定代码加载FullCalendar。创建一个像 LoadCalendar 这样的jquery函数,并在该函数中放置以下代码,并在jquery中的document.ready函数上调用此函数。

 $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        locale: '@companyCulture',
        defaultDate: Date.now(),
        defaultView: 'month',
        navLinks: true, // can click day/week names to navigate views
        editable: false,
        eventLimit: true, // allow "more" link when too many events
        dayClick: function (date, allDay, jsEvent, view) {
            //$("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm") + '');
            $("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm A") + '');
            $("#hdRDate").val(moment(date).format());
            emptyEventDetails(date);
            // $("#AddEventModel").modal();
        },
        eventClick: function (calEvent, jsEvent, view) {
            $.ajax({
                type: "GET",
                async: false,
                cache: false,
                url: "@Url.Action("GetEventById", "Events")",
                data: {
                    Eventid: calEvent.id
                },
                success: function (data) {
                    emptyEventDetails();
                    //$.each(data.data, function () {
                    //    alert(this["Title"]);
                    //    var color = 'orange';
                    //    var Title = this["Title"];
                    //    //addCalanderEvent(this["EventID"], this["EventDate"], Title, color);
                    //});

                }

            });

            //$("#lblDate").html('' + calEvent.EventDate + '');
            //$("#hdRDate").val(calEvent.EventDate);
            //$("#AddEventModel").modal();
        }
    });

添加事件:使用以下代码在FullCalendar中添加事件

 var eventObject = {
        title: title,
        start: moment(start).format("MMMM DD,YYYY hh:mm A"),
        end: moment(end).format("MMMM DD,YYYY hh:mm A"),
        id: id,
        color: colour
    };

    $('#calendar').fullCalendar('renderEvent', eventObject, true);

OR

$('#calendar').fullCalendar( 'addEventSource', newSource); //Add a new source 

删除所有事件::我正在尝试删除fullcalendar插件中的所有事件源。我目前正在使用

的组合
 $('#calendar').fullCalendar('removeEvents') //Hide all events
 $('#calendar').fullCalendar('removeEventSource', $('.Source').val()) //remove eventSource from stored hidden input

OR

$('#Calendar').fullCalendar( 'removeEvents').fullCalendar('removeEventSources');  //Removes all event sources

答案 1 :(得分:1)

以下是我用来获取此功能的完整代码:

HTML:

<form id="#calendar_list">
<input class="checkbox" type="checkbox"  checked>Event Group 1<br> 
<input class="checkbox1" type="checkbox"  checked>Event Group 2<br> 
<input class="checkbox2" type="checkbox"  checked>Event Group 3<br> 
</form>

使用Javascript:

    $(".checkbox").change(function() {
    if(this.checked) {
      $('#calendar').fullCalendar( 'addEventSource',  'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
    }
    else{
    $('#calendar').fullCalendar( 'removeEventSource',  'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
    }
});