javascript - JQuery Full Calendar - edit calendar view after initialization - Stack Overflow

At the beginning of the script, I have many options passed on to the calendar. After it is initialized,

At the beginning of the script, I have many options passed on to the calendar.

After it is initialized, executing the following doesn't change the view of the existing calendar, but creates a new calendar instead:

$('.calendar-container').fullCalendar({
   defaultView: 'agendaWeek'
});

Question: how do I change the view of the calendar which already exists in the .calendar-container div?

At the beginning of the script, I have many options passed on to the calendar.

After it is initialized, executing the following doesn't change the view of the existing calendar, but creates a new calendar instead:

$('.calendar-container').fullCalendar({
   defaultView: 'agendaWeek'
});

Question: how do I change the view of the calendar which already exists in the .calendar-container div?

Share Improve this question edited Apr 30, 2015 at 15:07 Adri w Ukraine 20k19 gold badges106 silver badges140 bronze badges asked Aug 2, 2013 at 12:50 OnionOnion 1,8322 gold badges25 silver badges42 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

FullCalendar only supports change of a few options after initialization, like height, contentHeight and aspectRatio. If you want to change other options, you should destroy the current calendar, and initialize FullCalendar again with the new options.

You might want to remember the current state, so you can recreate it after the calendar has been destroyed. Include this callback in your FullCalendar options, and save the view in some variable that you can access after the calendar has been destroyed:

viewDisplay: function(view) {
    latestView = view;
}

Then you can call these methods after the calendar has been reinitialized, and recreate the state the calendar was in (like the same view and date range):

$("#calendar").fullCalendar('changeView', latestView.name);
$("#calendar").fullCalendar('gotoDate', latestView.start);

If you go through their documentation it is clearly specified.

There is a function to change the view.

.fullCalendar( 'changeView', viewName )

http://arshaw./fullcalendar/docs/views/changeView/

Well imagine you want to change eventsources....

function getSources(switcher){    

        if(switcher== "option1"){
            return [othersources.opt1,othersources.opt2];

        }else{
            if(switcher== "option2"){                       
            return [othersources.opt3];}
        }      
    }


...
eventSources: getSources(switcher),
...

You can find a way to change any property with a simple function...

Hope it helped...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744938510a4602174.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信