Quantcast
Channel: MetroStar Systems Blog » C#
Viewing all articles
Browse latest Browse all 11

Creating a Custom SharePoint Calendar Rollup

$
0
0

A few months ago I had a requirement to rollup multiple SharePoint 2010 Calendars into one centralized calendar. I initially thought, “overlays make that a piece of cake!” Little did I know, I was about to embark on a much longer adventure than I anticipated…

It wasn’t long after I started adding the calendar overlays that I remembered the calendar overlays do not open in modal windows, they open in a new tab. To be honest, I really don’t understand why it’s setup that way considering everything else opens in a modal window. Then I thought this should be easy enough to hack with some jQuery, so I did some searching and sure enough there are a few hacks out there, such as this one: Open items in calendar overlay in Popup instead of new window in SharePoint 2010. That works nicely, however if you have to expand any days to see more items, those links get reset back (and apparently this is not supported due to the fact that you’re accessing code that is not intended for public use)…so I dug through some of the SP.UI JavaScript and it looks like the grid was getting rebuilt when you expanded/collapsed the calendar. I then worked some additional JavaScript in to auto expand the calendar, however that didn’t do the job either because if the calendar was collapsed, the links were reset.

It seemed that no matter how hard I tried I just couldn’t seem to accomplish what I wanted from the OOB calendar overlays. Consequently, I put on my Developer hat and started on Plan B: the SPCalendarView. Again I thought this should be simple enough…nope!

I started out following the steps on this post to setup a simple calendar Creating SharePoint global calendar but for some reason it wasn’t displaying any items. After looking around a bit, it turns out that the SPCalendarView will only display items in SharePoint 2010 if you set the EnableV4Rendering property to false, so I did that and it worked, but the calendar looked like SharePoint 2007 (Nasty!). Sooooo I spent some time trying to see if there was a way around that, and I honestly couldn’t find anything that worked. By this point I was ready to start pulling out hair…I even tried using the Bamboo Calendar Web Part, which works great, but I don’t want to have to buy it.

I then went back and tried some further JavaScript hacking to the OOB calendar, but in the end failed, so finally I just decided to go back to the SPCalendarView and hack it up as needed. In the end I think I came up with a pretty good alternative to the OOB Calendar Overlays. Below is an image of what it looks like.

Custom Calendar Rollup

Not too shabby if you ask me. So I basically just added an SPCalendarView to a Visual Web Part, added some properties to the Web Part so that you can configure up to 10 Calendars from the Tool pane, added a bunch of CSS to override the styling of the calendar to make it look more like a SharePoint 2010 calendar, added 10 colors to the CSS to be used for the color coding, and added some jQuery to perform a little further formatting after the Web Part loads.

I’m not going to go through the code because I think it is pretty straight forward however I do have a few final things to note:

  • It does retain a lot of the characteristics of the SharePoint 2007 calendar such as: The page refreshing when you click links as opposed to the nice AJAX that you get in SharePoint 2010, the Day, Week, Month links are within the Web Part (not the ribbon), the calendar coloring is based on the standard SharePoint theme, so if you want different colors you’ll have to update them, and I decided to leave the borders within the Calendar.
  • This will not work properly if you add more than 1 of these Web Parts to a single page (not sure why you would need to), due the fact that jQuery is being loaded in through the Web Part, however that wouldn’t be hard to change.
  • You cannot add items to the calendars through this Web Part, that would either be done through the normal lists, or you would need to add your own logic for that.
  • This Web Part does not handle recurring events very well, they basically get stretched out as 1 event from the start date to the end date.
  • This issue also affects SharePoint 2013, so it should work in 2013, however it would likely need some formatting.

So that is basically it. I figured given the difficulty that I had with this, and the lack of actual solutions online that are free, I would share what I learned and the end product. Hopefully this is helpful as at least a starting point.

Here is the zipped up Visual Studio solution package: Calendar Rollup.zip

To use the solution without making any changes, just grab the WSP from the solution package, deploy it in your farm to a Web Application, add the Web Part to your page, Edit the Web Part, specify some list names under the Configurations section, click OK, and refresh the page.

The post Creating a Custom SharePoint Calendar Rollup appeared first on MetroStar Systems Blog.


Viewing all articles
Browse latest Browse all 11

Trending Articles