2

Is there a way to only show the work week (Monday-Friday) within a calendar webpart. I found a CSS that works in a CEWP on the main calendar, but doesn't transfer into the webpart.

I've tried a few scripts (JS) within CEWP, but I think they are for SP 2010 and did not work.

Any help is appreciated. Thanks!

3
3

See this post: Hide weekend in calendar SharePoint 2013

end result from one of the comments in the related post: script used:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function(){
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.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
table.rows[c].cells[7].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 7)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[6].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 6)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[5].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 2)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
      }
     }
    }
   }
  } 
});
function month(){

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.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
table.rows[c].cells[7].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 7)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[6].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 6)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[5].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 2)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
}

     }
    }
   }
  }
 }
 //For week view
 function week(){

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-detail")
{
for (var c = 0; c < table.rows.length; c++)
{
if (table.rows[c].cells.length == 8)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
table.rows[c].cells[7].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 7)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[6].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 6)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[5].style.visibility = "hidden";
}
else if (table.rows[c].cells.length == 2)
{
table.rows[c].cells[0].style.visibility = "hidden";
table.rows[c].cells[1].style.visibility = "hidden";
}

     }
    }
   }
  }
 }



$( "#WPQ2_nav_prev_a" ).click(function() {
 month();
})
$( ".ms-picker-table" ).click(function() {
month();
})
$( "#WPQ2_nav_next_a" ).click(function() {
month();
})
setInterval(function () { month()}, -10000);
setInterval(function () { month()}, -10000);
setInterval(function () { week()}, -10000);

 </script>

enter image description here the weekend columns are just blank for the view, they don't actually disappear from the list as they are needed for the calendar to technically functionality to actually work.

An Outlook alternative for this would be to have them import the calendar to Outlook and use the "work week" button in the ribbon to do the same thing.

5
  • Does this work for calendars within the web part? – cbbrown Oct 13 '17 at 17:57
  • It doesn't remove the days from the Date picker columns, it just hides the Sunday (left column) and Saturday (right column) in the Calendar view for (Month / Week). The days still technically exist. You may have to use validation logic or column comments to help the users understand that only weekdays are valid. – Chris G Oct 13 '17 at 18:09
  • which script did you use in the CEWP? – cbbrown Oct 13 '17 at 18:23
  • That worked on the calendar page and the calendar web part (had to do two separate CEWP, but it worked. Thanks!! – cbbrown Oct 13 '17 at 18:32
  • 1
    Nice! by the way I found some validation logic that you can use to help enforce that people only choose weekdays for the start date fields. social.technet.microsoft.com/Forums/sharepoint/en-US/… – Chris G Oct 13 '17 at 19:05
0

You can only hide events on certain day but you can't hide a Day. SharePoint out of the box template will display your calendar as Week, Month or a year but it will not hide a day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.