Remove Saturday & Sunday from a calendar view in SharePoint

Search

Accessible SharePoint WebSites
Download ARF

Remove Saturday & Sunday from a calendar view in SharePoint

http://blog.thekid.me.uk

I recently answered a question about removing Saturday & Sunday from a calendar view to save screen real estate. Whilst there maybe other ways involving CAML, I thought JavaScript would be quick and easy. It appeared to work quite well and so I thought I would share it here.

Essentially you need to add some javascript to your default.master...

image

This will change this calendar...

image

Into this...

image

Here is the script if you want to cut 'n' paste it...

   <script>
           var oTable = document.getElementById("CalViewTable1");
           if (oTable != null)
           {
               oTable = oTable.rows[2].cells[0].firstChild;
            for (var c=0; c<oTable.rows.length; c++)
            {
                if (oTable.rows[c].cells.length == 9)
                {
                    oTable.rows[c].cells[0].style.display = "none";
                    oTable.rows[c].cells[1].style.display = "none";
                    oTable.rows[c].cells[2].style.display = "none";
                    oTable.rows[c].cells[8].style.display = "none";
                }
                else if (oTable.rows[c].cells.length == 7)
                {
                    oTable.rows[c].cells[0].style.display = "none";
                    oTable.rows[c].cells[6].style.display = "none";
                }
                else if (oTable.rows[c].cells.length == 2)
                {
                    oTable.rows[c].cells[0].style.display = "none";
                    oTable.rows[c].cells[1].style.display = "none";
                }
            }
           }
   </script>

Posted by Vincent Rothwell on Sunday, 30 Mar 2008 15:42  - 25 Comments
Orininally printed from http://thekid.me.uk - Copyright Vincent Rothwell 2007
 

Comments

Sunday, 27 Jul 2008 10:36 by FSBO Louisville
Crazy, thanks for the info!!

Sunday, 27 Jul 2008 10:36 by Dean
this is great, i've asked this question in the past and never got an answer. it's too bad mods like this can not be done through the browser, but this should work for us.

Sunday, 27 Jul 2008 10:36 by Vince
Dean, If you use IE7Pro then you can get IE to automatically load the script for you. That way you don't need to modify default.master Vince

Sunday, 27 Jul 2008 10:36 by Dean
Vince, how do I do I get the script to load automatically? Dean

Sunday, 27 Jul 2008 10:36 by Sabrish
Vince, How can i get this to work with week view? In week view the page looks completely disorted. If possible please explain the thing that you are hiding, so that I can modify the script to work with week view. Thank you. Sabrish

Sunday, 27 Jul 2008 10:36 by Sabrish
Vince, Another quick question, the above method doesnt work in Mozilla. ie when we open the page in Mozilla we will still be able to see the weekends. Any ideas on how to fix this? Cheers, Sabrish

Sunday, 27 Jul 2008 10:36 by Sabrish
Vince, I got it to work for week view. The script is attached below. <SCRIPT language="javascript"> var oTable = document.getElementById("CalViewTable1"); if (oTable != null) { oTable = oTable.rows[2].cells[0].firstChild; for (var c=0; c<oTable.rows.length; c++) { //alert(oTable.rows[c].cells.length); if (oTable.rows[c].cells.length == 9) { oTable.rows[c].cells[2].style.display = "none"; oTable.rows[c].cells[8].style.display = "none"; } else if (oTable.rows[c].cells.length == 23) { oTable.rows[c].cells[2].style.display = "none"; oTable.rows[c].cells[3].style.display = "none"; oTable.rows[c].cells[4].style.display = "none"; oTable.rows[c].cells[20].style.display = "none"; oTable.rows[c].cells[21].style.display = "none"; oTable.rows[c].cells[22].style.display = "none"; } } } </script> Please let me know how to make it work in Mozilla. Cheers, Sabrish

Sunday, 27 Jul 2008 10:36 by Sabrish
It fails over after this line in Mozilla. oTable = oTable.rows[2].cells[0].firstChild; Please help!!! Cheers, Sabrish

Sunday, 27 Jul 2008 10:36 by Flat Fee MLS
I wish I could help, I am a little lost myself.

Sunday, 27 Jul 2008 10:36 by Andy
To apply it on calendar, you can: add a content editor webpart add the script in the source hide the content editor webpart

Sunday, 27 Jul 2008 10:36 by ads
is it strange that in my default master of the site it doesnt have a <form> tag? I have a calendar though? ;)

Sunday, 27 Jul 2008 10:36 by ads
is it strange that in my sites calendar default master i dont have a <form> or </form> tags?

Thursday, 31 Jul 2008 12:42 by Turkey
thanks docs perfect you It fails over after this line in Mozilla. oTable = oTable.rows[2].cells[0].firstChild; Please help!!!

Friday, 1 Aug 2008 10:02 by Hat
Andy, do you have more detail to your Content Editor Webpart trick??

Friday, 1 Aug 2008 10:36 by Hat
Andy, do you have more detail to your Content Editor Webpart trick??

Friday, 1 Aug 2008 12:39 by Hat
Andy, do you have more detail to your Content Editor Webpart trick??

Friday, 1 Aug 2008 01:05 by Hat
Andy, do you have more detail to your Content Editor Webpart trick??

Monday, 4 Aug 2008 02:34 by CodePirate
This works great when displaying the blank calendar... However everything gets thrown off once and item is added to the calendar. I start getting blank lines thrown in. Anyone else getting this, or is it just me? BTW, I added the code using the content editor webpart and it works just great as long as the content editor is placed after the calendar on the page.

Monday, 4 Aug 2008 02:55 by CodePirate
This works great when displaying the blank calendar... However everything gets thrown off once and item is added to the calendar. I start getting blank lines thrown in. Anyone else getting this, or is it just me? BTW, I added the code using the content editor webpart and it works just great as long as the content editor is placed after the calendar on the page.

Tuesday, 5 Aug 2008 11:50 by Hat
Also, I realized that when I apply the script and remove Sat/Sun columns, the M-F columns increase in size and eliminate the benefit of the script (for my purposes). I'm trying to fit a Month View, M-F Calendar on the home default.aspx page, within the right or left zone, and not have a side scroll bar. It's been suggested that additional JavaScript need be written to control the column width in the calendar. Thoughts/Suggestions?

Monday, 8 Dec 2008 09:39 by Chris Howell
Just wondering if there is any progress on this code? I'm trying to combine it with a style from here: http://pathtosharepoint.wordpress.com/2008/10/11/tiny-sharepoint-calendar-2/ but I end up with vertical lines and lots of space.

Wednesday, 17 Dec 2008 09:45 by Christophe
I have written my own solution: http://pathtosharepoint.wordpress.com/2008/12/17/calendar-weekdays-only/ It should address the issues reported in the above comments (week view, items added to the calendar, adjust width). Also, it works in Firefox. Christophe

Wednesday, 14 Jan 2009 08:06 by

Wednesday, 10 Jun 2009 02:31 by Jerry
Thanks for the script. It's working fine for me except that there are still table visible for Saturday and Sunday positions, even if the contents are not shown. Is it related to my my Sharepoint settings? Thanks a lot if you could help here.

Friday, 26 Jun 2009 03:03 by Tim
Thanks, everyone, and especially Christophe. Works just fine, even though I too would be pleased if Sat & Sun disappeared completely.



Url

Email

Comments