How can I set Fullcalendar options dynamically

不打扰是莪最后的温柔 提交于 2019-11-29 05:56:02
the hand of NOD

I don't know if it is still relevant but I can change the options with the following statement:

example for selectable:

$('#calendar').fullCalendar('getView').calendar.options.selectable = false;
$('#calendar').fullCalendar('render'); // rerender to see visual changes

Though it's not dynamically but at least you don't have to destroy the whole calendar and refetch your events :-)

This functionality has been officially release in v2.9.0: http://fullcalendar.io/docs/utilities/dynamic_options/

Bobby B

Can't be done without recreating the calendar.

Update: Can be done in v 2.9: See below

This way you can change as many calendar options you like:

// save the calendar options in a variable
var calendarOptions = $('#calendar')
     .fullCalendar('getView')
     .options;

// make your changes to the calendar options
// I wanted to change the slotDuration
calendarOptions.slotDuration = '00:20:00';

// destroy the calendar
$('#calendar')
     .fullCalendar('destroy');

//Lets load the calendar with the new options
$('#calendar')
     .fullCalendar(calendarOptions);

Hope this helps. Thanks.

There's an open issue for this functionality here:

https://code.google.com/p/fullcalendar/issues/detail?id=293

just me dude's answer is actually the only way I found myself.

This is just an addendum to this former answer : If you want to change the editable option, which is very useful if you want to lock the events for asking confirmation on a change before updating your database, it's a little more tricky. In case it can save some time to someone I dump the code:

var view = $('#calendar').fullCalendar('getView');
view.calendar.options.editable = false;
view.calendar.overrides.editable = false;
view.calendar.viewSpecCache.month.options.editable = false;
view.calendar.viewSpecCache.agendaWeek.options.editable = false;
view.calendar.viewSpecCache.agendaDay.options.editable = false;
$('#calendar').fullCalendar('render');

You obviously change all those false to true to unlock.

valar morghulis

This code just did fine for me. Call this function anywhere and pass as many custom variables to it, but don't forget to destroy the previous calendar first

function initializeCalendar( timeIntervalCustom ) {
  $('#calendar'+id).fullCalendar({
  slotMinutes: timeIntervalCustom,

});                       

}

$('#calendar').fullCalendar("destroy");
initializeCalendar(10);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!