Fullcalendar event source not loading on first page load
Hello all,
I am trying to figure out when I load a page with fullcalendar on it the event source that I want to display in month view is not being loaded. I have to click on the Week view then back on the month view and the display I want appears then. I will post snippets of code to illustrate what I have done:
- $(document).ready(function() {
-
- $('#calendar').fullCalendar({
- header:{
- right: 'prev,next today',
- center: 'title',
- left: 'month, agendaWeek, resourceDay'
- },
- minTime: '6:00am',
- maxTime: '8:00pm',
- events: '/json-events.php',
- resources:'./json-resources.php',
-
- viewDisplay: function (view) {
- if (lastView == undefined) {
- lastView = 'firstRun';
- }
- //alert("viewname: "+ view.name + "lastView: " + lastView);
- if (view.name != lastView) {
- if(view.name == "month") {
- // alert("month");
- $("#calendar").fullCalendar("removeEventSource","/json-events.php");
- $("#calendar").fullCalendar("addEventSource", "/json-test.php");
- $("#calendar").fullCalendar("removeEventSource","/json-events.php");
-
- // $("#calendar").fullCalendar("rerenderEvent");
- // alert("add current event");
- // $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
- // alert("remove current event");
- // $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
- // alert("remove added event");
- }
-
- if (view.name == "agendaWeek") {
- // alert("in month: Delete litesource");
- $("#calendar").fullCalendar("addEventSource", "/json-events.php");
- $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
- $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
- }
-
- if (view.name == "resourceDay") {
- // alert("in day: add litesource");
- $("#calendar").fullCalendar("addEventSource", "/json-events.php");
- $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
- $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
- }
-
- lastView = view.name;
- }
- // alert("Done");
- }
- });
- });
The above code works as I want it to once I click through the views. Initially when I load the page with fullcalendar on it, it displays the month view and a list of events on a given day. I have included a few pictures of what is happening as well.
On initial page load:
After clicking week then back to month:
Thanks to whoever helps out.