search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Navigator vs. Calendar week shown in week-view

Asked by Mike
4 years ago.

Just wondering if there is any way to sync up the calendar week that is highlighted in the navigator with the "work-week" displayed in the calendar itself on the first load of the page? Maybe a parameter I've missed?

So for example it is Sunday June 9th today... upon first load of the page navigator has the week of June 9th-15th highlighted... but the calendar data that is loaded is for the "work-week" of June 3rd-7th. I'm guessing that the logic that's hitting is that the "work-week" of June 10th-14th has not started yet.

If I actually click on the week of 9th-15th on the navigator, then the correct data is loaded.

As it stands It's just too easy for users to to see the proper week highlighted in the navigator and not notice that it's actually displaying last week's calendar still.

Thoughts?

Comment posted by Dan Letecky [DayPilot]
4 years ago.

Mike,

You can specify the initial selection using selectionDay property of DayPilot.Navigator. If not specified, it will use today's date.

var nav = new DayPilot.Navigator("nav");
nav.selectionDay = DayPilot.Date.today().addDays(7);  // next week
nav.onTimeRangeSelected = function(args) {
  dp.startDate = args.start;
  dp.update();
};
// ...
nav.init();

When initializing the Calendar, make sure that you are using this date as startDate:

var dp = new DayPilot.Calendar("dp");
dp.startDate = nav.selectionDay;
// ...
dp.init();

All subsequent changes of the Navigator selection will be mapped to the Calendar using nav.onTimeRangeSelected event handler. So the other option is to call select() after both components are initialized:

var nav = new DayPilot.Navigator("nav");
nav.onTimeRangeSelected = function(args) {
  dp.startDate = args.start;
  dp.update();
};
// ...
nav.init();

var dp = new DayPilot.Calendar("dp");
dp.startDate = nav.selectionDay;
// ...
dp.init();

nav.select(DayPilot.Date.today().addDays(7));

Please let me know if it didn't help.

Comment posted by Mike
4 years ago.

Hi Dan

First I'll note that today on Monday June 10th my existing code operated as I would have expected it to (nav displays Jun 9-15, calendar displays Jun 10-14). So appears that my thoughts above on the current "work-week" not having started were correct.

As to your example, I don't need to play with the navigator date as it is showing the week that I expected already (but code noted for future).

I was not explicitly specifying a dp.startDate value on the calendar itself though so I've now assigned that to nav.selectionDay as suggested. It appears to be working fine at this point, will see if that holds true next Sunday.
Worst case if it doesn't work I can fudge the startDate if the calendar is viewed on a Sunday. :-)

Answer posted by Dan Letecky [DayPilot]
4 years ago.

Mike,

Thanks for the update! After checking the implementation it turned out that the Calendar used hardcoded Monday as the first day of week instead of reading the locale. It should be fixed now in the latest sandbox build (2019.2.3883):

https://javascript.daypilot.org/sandbox/

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.