How can I set Fullcalendar options dynamically

孤街醉人 提交于 2019-12-18 04:34:28

问题


How can I set the minTime and maxTime options after the calendar is created?

I tried the following, which doesn't work:

$('#calendar').fullCalendar('option', 'minTime', 7);
$('#calendar').fullCalendar('render');

回答1:


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 :-)




回答2:


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




回答3:


Can't be done without recreating the calendar.

Update: Can be done in v 2.9: See below




回答4:


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.




回答5:


There's an open issue for this functionality here:

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




回答6:


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.




回答7:


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);


来源:https://stackoverflow.com/questions/13432014/how-can-i-set-fullcalendar-options-dynamically

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