Wednesday, May 1, 2013

SharePoint Calendar: Expand all events on load

This is my approach to expand all calendar events on load, but if you have a better way, please share!

On the calendar page, add a reference to jQuery and also place a style tag to hide the "expand/collapse" links on load:

<style>
 .ms-cal-nav{display:none;}
</style>


Hook into the existing SharePoint calendar load function:

_spBodyOnLoadFunctionNames.push('changeCalendarEventLinkIntercept');

function changeCalendarEventLinkIntercept()
{
  var OldCalendarNotify4a = SP.UI.ApplicationPages.CalendarNotify.$4b;
  SP.UI.ApplicationPages.CalendarNotify.$4b = function () 
    {
      OldCalendarNotify4a();
      changeCalendarEventLinks();
    }
}


In the function call, find all anchor tags with the attribute evtid marked as 'expand_collapse' and click on the hyperlink:

function changeCalendarEventLinks()
{
//expand all
 $("a[evtid='expand_collapse']").each(function(){
  $(this)[0].click();
 });
}

5 comments:

  1. Does this work for Office 365?

    I tried it but could not get it to work.

    ReplyDelete
  2. Have you placed a jquery reference before this script?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. It seems clean until I paste in the last section. Then I get "server tag is not well formed".
    ----------------
    function changeCalendarEventLinks()
    {
    //expand all
    $("a[evtid='expand_collapse']").each(function(){
    $(this)[0].click();
    });
    }

    ReplyDelete
  5. Thanks, that saved me some time :-)

    ReplyDelete