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";
}

}

}
}
}

5 comments:

subbu said...

Hi Prakash ..
Tx for the script ...but it is not working properly...Items are not showing up in correct way .Please can you provide me the changed script

JennS said...

Thank you for the script, it does eliminate saturday and sunday from the monthly view, but it also collapses all of the items on the calendar to the top where the names of the days of the week are and clicking the 'expand all' button on the ribbon doesn't display them correctly either. Do you happen to know a fix for this? or am i doing something wrong?

Unknown said...

Did you guys ever find a solution for this? I've been trying several scripts and none of them work.

Unknown said...

Hi All/Prakash,

Do you have working code in which it will run on SharePoint 2010. Also I found another code and its working for showing weekdays on calendar.
https://social.technet.microsoft.com/Forums/office/en-US/0fc34764-6988-46aa-b516-b49ba33b0206/any-of-hidingremovingdisabled-weekends-sat-and-sun-from-sharepoint-online-2013-calendars?forum=sharepointgeneral

But when you add new items the new items are not showing correctly and go to top of week and user have to refresh page to get the items displayed on the particular date added.
I have been searching and trying for couple of days. any help would be appricated.

Regards,
Deepak

Unknown said...

So, there is no way or easy way to remove weekends from a Calendar Month view in SP2010?