Thursday, December 9, 2010

Remove Saturday & Sunday from a calendar view in SharePoint 2010

Recently I had a requirement to remove saturday, Sunday from the default calendar view in SharePoint 2010.

I was looking for a solution and found the below blog useful:
http://blog.thekid.me.uk/archive/2008/03/30/remove-saturday-sunday-from-a-calendar-view-in-sharepoint.aspx

but the above solution works fine with SharePoint 2007 alone.

I made a small tweak to the above script and made it work for SharePoint 2010 Calendar View.

Please add a content editor webpart in the calendar view page and add the below script in the Source Editor of Content Editor Web part.

Here you go the script for the same: [Use this within

Script block]

var oTable = document.getElementsByTagName("TABLE");
if (oTable != null) {

for (i = 0; i < oTable.length; i++)
{
var table = oTable.item(i);
if (table.className == "ms-acal-month")
{
for (var c = 0; c < table.rows.length; c++)
{
if (table.rows[c].cells.length == 8)
{
table.rows[c].cells[0].style.display = "none";
table.rows[c].cells[1].style.display = "none";
table.rows[c].cells[7].style.display = "none";
}
else if (table.rows[c].cells.length == 7)
{
table.rows[c].cells[0].style.display = "none";
table.rows[c].cells[6].style.display = "none";
}
else if (table.rows[c].cells.length == 6)
{
table.rows[c].cells[0].style.display = "none";
table.rows[c].cells[5].style.display = "none";
}
else if (table.rows[c].cells.length == 2)
{
table.rows[c].cells[0].style.display = "none";
table.rows[c].cells[1].style.display = "none";
}

}

}
}
}