Skip to content

Script Fix to Expand All Items in SharePoint 2013 Calendar to Show More Than Three Using jQuery

by on August 16, 2016

I’m not really sure why Microsoft made the decision to auto-hide when you have more than three items, then make it so difficult to reset (bad Microsoft, no cookie!), but this is a quick workaround I have confirmed works even with a large number of overlay calendars and lots of events.

For testing, I recommend setting the final setTimeout to 2000 to make sure the calendars and events are all loading, then play with your final setting – I found 800 ms worked well for my environment with a bit of wiggle room and not too much lag.

JavaScript for More Than 3 Items in SharePoint Calendar

I like to put this in the Site Collection root Style Library folder or a custom AdvancedContent library folder, then reference it in a Content Editor Web Part on the calendar page where it is needed for reusability. You should also be able to just throw it in a script block, assuming you have jquery files to reference. A similar approach can be used to make a pretty and persistent Expand All button if needed.


<script src="https://sharepoint.com/it/Style Library/jquery.1.11.1.min.js"></script>
<script>
$( document ).ready(function() {
	//$("div").css("color","red");    
    
    
    var pollCount = 0;
    checkCalendar($);

function checkCalendar($) {
	//alert("Checking for Calendar load");
   //stop after 10 seconds
   if (pollCount > 20)
      return;
   //if the calendar hasn't loaded yet, then wait .5 seconds
   //if ($('.ms-acal-title a').length < 1) {
   if ($('.ms-cal-nav').length < 1) {
      pollCount++;
      setTimeout(function(){checkCalendar($);}, 500);  
      //alert("Checking " + pollCount);   
   }
   else {
      //the calendar has loaded, so do work
      	setTimeout(function(){  
      	//alert("Found title, running expand");
         var calendar = SP.UI.ApplicationPages.CalendarInstanceRepository.firstInstance();
         if (calendar && typeof calendar.expandAll === 'function') {calendar.expandAll();}
      	}, 800);
         

      //});
    }
}

    
});
</script>


Have a cup of tea! You’re Done!

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: