2

I would like the Full calendar scheduler to remember the current view and date range. I've got the view working, but it always defaults to the current date.

Code snippet:

var defaultView = (localStorage.getItem("fcDefaultView") !== null ? localStorage.getItem("fcDefaultView") : "timelineFiveDays");
var defaultStartDate = (localStorage.getItem("fcDefaultStartDate") !== null ? localStorage.getItem("fcDefaultStartDate") : null);
var defaultEndDate = (localStorage.getItem("fcDefaultEndDate") !== null ? localStorage.getItem("fcDefaultEndDate") : null);

$('#calendar').fullCalendar(
{    
    defaultView: defaultView,
    visibleRange:
    {
    start: defaultStartDate,
    end: defaultEndDate
    },
    viewRender: function(view, element)
    {  
    localStorage.setItem("fcDefaultView", view.name);
    localStorage.setItem("fcDefaultStartDate", view.start);
    localStorage.setItem("fcDefaultEndDate", view.end);
    }
}

Many thanks for any help

Roxy521
  • 71
  • 5
  • I use cookies to do this. learn to save and load cookie information. – warath-coder Mar 14 '18 at 22:00
  • how about setting `defaultDate` instead of visibleRange? – ADyson Mar 15 '18 at 14:40
  • I finally got it working by using the gotoDate var defaultView = (localStorage.getItem("fcDefaultView") !== null ? localStorage.getItem("fcDefaultView") : "timelineFiveDays"); var defaultStartDate = (localStorage.getItem("fcDefaultStartDate") !== null ? localStorage.getItem("fcDefaultStartDate") : moment()); defaultView: defaultView, $('#calendar').fullCalendar('gotoDate', defaultStartDate); – Roxy521 Mar 16 '18 at 15:11
  • you can post that as an answer for future readers - you can answer your own question and mark it accepted. But I bet you can also do it by setting `defaultDate` directly instead of using the goToDate method after initializing the calendar. – ADyson Mar 20 '18 at 11:27

1 Answers1

2

I finally got it working by using the gotoDate

var defaultView = (localStorage.getItem("fcDefaultView") !== null ? localStorage.getItem("fcDefaultView") : "timelineFiveDays"); 
var defaultStartDate = (localStorage.getItem("fcDefaultStartDate") !== null ? localStorage.getItem("fcDefaultStartDate") : moment()); 
defaultView: defaultView, 
$('#calendar').fullCalendar('gotoDate', defaultStartDate); 

As mentioned by @ADyson I might try the defaultDate rather than using the goToDate method

Roxy521
  • 71
  • 5