So I have searched and searched and searched. First off, NO a Gantt Chart will not do what is desired. :) Honestly, I am not even sure why that was given an upvote in the threads I saw that answer given.

So here is the scenario: a 4x3 table inserted onto a page, each cell with a Calendar webpart in it.

I have managed to locate a script that allows one to adjust the displayed month, but it seems to only adjust the first calendar it runs into regardless of what WPQ# is used. Obviously the call is somewhat correct, but perhaps the code is in the wrong order.

The script I found is meant to advance view 1 month prior to today's month... I can tweak that... no worries... just need to be able to to use this (or something else) to advance the months properly to reflect the full calendar across the 12 webparts.

Thanks for looking!

<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
var itv;
var s;
var nextMonth;
var monthAry = ["January","Feburary","March","April","May","June","July","August","September","October","November","December"];
    var d = new Date();
    var dd = d.getDate();
    var mm = d.getMonth()+1;
    var yy = d.getFullYear();
    var mmm = mm+3; // this changes
    s = mmm+"/"+dd+"/"+yy;  
    nextMonth = monthAry[mm];
    itv = setInterval(ready, 1000);
function ready()
    // I have tried using ' instead of "
    // I have tried different WPQs
    // I have tied #WebPartWPQ3
    var header = $("#WPQ3_nav_header").html().trim();

THIS HAS BEEN ANSWERED AND RESOLVED. Info, code, and pic below Thank you very much Robin in OR!
Had to tweak it some, but...

<script type="text/javascript">
$(document).ready(function() {

    document.getElementById('divStatus').innerHTML = 'Starting';    

    var d = new Date();
    var myYear = d.getFullYear();
    //myYear = myYear+1;     // Uncomment line on next years page

    document.getElementById('divStatus').innerHTML = myYear;

    var dateField = new Date('1/1/'+myYear);
    var dateField = new Date('2/1/'+myYear);
    var dateField = new Date('3/1/'+myYear);
    var dateField = new Date('4/1/'+myYear);
    var dateField = new Date('5/1/'+myYear);
    var dateField = new Date('6/1/'+myYear);
    var dateField = new Date('7/1/'+myYear);
    var dateField = new Date('8/1/'+myYear);
    var dateField = new Date('9/1/'+myYear);
    var dateField = new Date('10/1/'+myYear);
    var dateField = new Date('11/1/'+myYear);
    var dateField = new Date('12/1/'+myYear);
    document.getElementById('divStatus').innerHTML = myYear +' Load Complete';



Here is an image of it working: Annual View using 12 Web Parts

And yes, I realize I did not use best practices by verifying that the web part was there or using an array... but it kept breaking... so thus... the current version.

Again thank you!

  • Looks great - good job! – Robin in Or Jan 10 '18 at 20:18

If you have regular calendar views on the page, you can use the built in function MoveToDate(date,'webpart') in a script on the page.. I use this on a page to keep multiple calendars in sync - when I change one calendar, another calendar follows along.



You just need the date you want to go to (this was a standard javascript Date() field, and the webpart number of the calendar you want to move.

Depending on what you're doing, you can move all calendars to the same month or week, for example, or if you're trying to do a year view, you can move one calendar to one month, the second one to that month+1, etc.

A fuller example. I use JQuery to determine when the page is finished building, but you could probably use other javascript functions to time it right. I'd have to go look.

To have 12 calendars for a single year, I might do something like this (we have JQuery local). I hate date math, so you might have to fuss with that a bit. I was trying to save on variables so I was adding one month at a time to the same date field.

<input type="button" onclick="javascript:loadThePage()" value="click me" />
<script type="text/javascript">
    function init() {
        setTimeout(loadThePage, 1000);
    function loadThePage() {
            var dateField = new Date('2/1/2018');

| improve this answer | |
  • Thank you for your response! I tried your solution, or attempted to at least. Based off what I was reading I should only need to run the snippet provided without all the other stuff I had before correct? And I am in the monthly view... :) Like this? <script type="text/javascript"> MoveToDate(dateField.format('12/01/2018','WPQ2') </script> – Chris Fells Jan 9 '18 at 23:30
  • So I have also tried putting this snippet into its own function as well as fixing the statement so it closed and ended itself properly MoveToDate(dateField.format('12/01/2018','WPQ2')); I have also tried removing the dateField.format from in front of the data... All with no joy. Am continuing to look for a way to resolve this. Also, to be clear all 12 webparts are for the same calendar... same calendar different month. – Chris Fells Jan 10 '18 at 14:29
  • Hmm, the code works if you attach it to a button, so the basic MoveToDate() works, but there's a timing problem with the calendar because it's asynch. Ive also tried waiting for sp.ui.applicationpages.calendar.js to load instead of just sp.js, but that didn't fix it. Also, my setMonth/getMonth logic isn't coded right - I'll have to fix that as well. – Robin in Or Jan 10 '18 at 19:05
  • Timing fixed - you can call a function that delays the call to the function that does the MoveToDate - this sample code, with hard coded dates, worked in SP2013. – Robin in Or Jan 10 '18 at 19:17

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.