11

How could I modify the fullcalendar plugin so that this saves the different click methods dayClick etc in a cookie? The next time this calendar is opened if would default to the user preference.

Already using the cookie plugin: https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js

Update of working cookie code following answer:

var calendarView = (!$.cookie('calendarDefaultView')) ? 'month' : $.cookie('calendarDefaultView');  
$calendar.fullCalendar({
    defaultView: calendarView,
    viewDisplay: function(view){
        $.cookie('calendarDefaultView', view.name, {expires:7, path: '/'});
    },
1
  • In version 2 I had to change viewDisplay to viewRender for this to work. ie. viewRender: function( view , element) { ....
    – PhoebeB
    Nov 24, 2015 at 9:46

1 Answer 1

11

The two fullcalendar methods you need are:

//pull viewName from the cookie or set as default
var viewName='month'; //or basicWeek, basicDay, agendaWeek, agendaDay
$("#fullcalendar").fullCalendar( 'changeView', viewName );

and

$('#fullcalendar').fullCalendar({
        viewDisplay: function( view )
        {
           //save your cookie here, it's triggered each time the view changes
        }
});

This should put you on the right path. I didn't look at saving the cookie b/c I think you have that under control.

4
  • If you need more detail just ask...I might need this functionality too in the future. Sep 24, 2012 at 21:54
  • Worked perfect thanks. I wanted to keep the cookie value clean and simple to I used: view.name. Updated my question with working code for cookie. Sep 24, 2012 at 22:28
  • 2
    Nice clean solution! Glad I could help. Sep 25, 2012 at 14:51
  • 1
    WIth fullcalendar v2, use the viewRender callback
    – fkoessler
    May 27, 2016 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.