none
How to make SP Calendar to only display tasks during work hours RRS feed

  • Question

  • When we create a tasks that starts on Friday and completes on Monday, SharePoint calendar shows the tasks as running Friday, Saturday, Sunday and Monday.  We usually don't work on the weekend and would like a way to block out the weekend when we're not working.  We can add a field that says if we're working on that day or not.  So we need something like this,

    If (TodayIsWorkingDay == true) Display tasks

    else Don't Display tasks

    Is there an API for the SP Calendar?  Here is a screen shot below.  Thanks.

    Friday, April 21, 2017 11:57 PM

All replies

  • Hi,

    Here is the sample solution for your reference, change the region settings of your site like below and add the style to script editor web part/content editor web part, you could check below thread for details:

    <style type="text/css">  
        table.ms-acal-month > tbody > tr > th:nth-of-type(1) {  
            display: none !important;  
        }  
          
        table.ms-acal-month > tbody > tr > th:nth-of-type(7) {  
            display: none !important;  
        }  
          
        table.ms-acal-month > tbody > tr > th:nth-of-type(8) {  
            display: none !important;  
        }  
          
        table.ms-acal-month > tbody > tr > td:nth-of-type(6) {  
            display: none !important;  
        }  
          
        table.ms-acal-month > tbody > tr > td:nth-of-type(7) {  
            display: none !important;  
        }  
    </style> 

    http://www.c-sharpcorner.com/UploadFile/fc34aa/hide-weekends-in-sharepoint-calendar-view/

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, April 24, 2017 7:24 AM
  • Hello Lee,

    Thanks for the help, but it doesn't completely work.  For example Normal work Task 3 runs from April 25 to May 2, but it gets left out of the 26 and 27. See attached.  There are addtional problems as listed on the comment secton of the link you provided.  I did try another solution, also from the comment section, but it also displayed multiday tasks incorrectly.

    Also I need to not block weekends when we plan to work.  We plan to have a field, workingWeekend, that is True if that task requires working over the weekend, else it'll be false.  So I need a way to cycle through every task on that week or month, and check if any workingWeekend is True.  If any are True weekends will not be hidden.

    Thanks,

    Billy

     image.

    Tuesday, April 25, 2017 1:22 AM
  • Hi,

    As per my knowledge, the render logic of Calendar events is processed by SP.UI.ApplicationPages.Calendar.js(you could find this js file in 15\TEMPLATE\LAYOUTS folder), if you want to customize the logic, you have to extend the logic.

    Here is one thread mentioned how to add custom logic for calendar for your reference.

    https://www.codeproject.com/Tips/759006/Enhancing-SharePoint-Calendar-sp-ui-applicationpag?msg=4894299#xx4894299xx

    I would suggest you set Monday as first day of week as this would take less effort for ‘workingWeekend’ logic.

    Here is the idea about how to achieve this:

    Retrieve the calendar events by jQuery and get event item id.

    Request REST api to get ‘workingWeekend’( add a column to calendar list).

    For rest api filter list items, you could check below thread.

    https://social.technet.microsoft.com/wiki/contents/articles/35796.sharepoint-2013-using-rest-api-for-selecting-filtering-sorting-and-pagination-in-sharepoint-list.aspx

    After getting the ‘workingWeekend’, if it’s false and cross weekend, update the style attribute.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 25, 2017 10:03 AM