Search code examples
jqueryschedulerdhtmlx

dhtmlx scheduler scheduler.getState().date reacting differently in Chrome vs. Firefox


I am trying to access the current date of the calendar to invoke a piece of code to adjust the first_hour and last_hour on the calendar. Here is the code.

$(".dhx_cal_today_button, .dhx_cal_prev_button, .dhx_cal_next_button")
                .click(
                        function() {
var formatFunc = scheduler.date.date_to_str("%D");
                            var dayTarget = formatFunc(scheduler.getState().date).toUpperCase();

                            scheduler.config.first_hour = dayScheduleAM[dayTarget];
                            scheduler.config.last_hour = daySchedulePM[dayTarget];
                            scheduler.config.mark_now = true;
                            scheduler.setCurrentView();
                            scheduler.updateView();

                        });

Now comes the weird part. When I run this in firefox, the scheduler has actually moved to the next or previous day while in Chrome it still shows the last day. For example, if I am on Monday and I click next, firefox debug shows scheduler.getState().date as Tuesday but chrome shows Monday still.

Any idea what is happening? Also, is there another way to wait for dhtmlx js to finish its processing before the .click is invoked? I do not want to write +1/-1 day logic as that would run into problem with firefox and who knows with what other future versions of browsers.


Solution

  • Issue can be caused by the order of events processing ( what goes first, the scheduler's or custom event handlers )

    Instead of attaching the handler, you can attach a handler to the onBeforeViewChange event

    scheduler.attachEvent("onBeforeViewChange", function(m,d, nm, nd){
      if (d*1 != nd*1{
           //active date was changed, place the custom logic here
      }
      return true;
    });