I am using the new Angular2 component, and setting up a DayPilot.Angular.Schedule component for a daily schedule. I am using two radiobuttons to set the cellDuration to either 5, or 10 minutes. These works great.
I want the schedule to scroll to a specific hour on init, and I am using the event "onAfterRender" to accomplish that. That also works great.
But when the radiobutton click event is fired, I also want to reset the scroll to the same hour, but the method Scheduler.control.scrollTo() does not scroll to the date that I input.
Here is my code:
Buttons in my template:
<input type="radio" name="cellduration" value="5" checked (click)="changeCellDuration($event)">5 min
<input type="radio" name="cellduration" value="10" (click)="changeCellDuration($event)">10 min
Here are my two functions in my component:
changeCellDuration(event) { //Called by the click event
this.cellDuration = event.srcElement.value;
this.scheduler1.config.cellDuration = this.cellDuration; //This works fine
this.resetScrollPosition(7); //This does not work
}
private resetScrollPosition(startHour: number) {
var startDate = (this.scheduler1.control.startDate as DayPilot.Date);
startDate = startDate.addHours(startHour); //Adds the nr of hours ontop of current date
this.scheduler1.control.scrollTo(startDate);
}
the function "resetScrollPosition" is the function used in my onAfterRender, so I know that it works
onAfterRender: args => {
this.resetScrollPosition(7);
}
I also tested to use the control.setScrollX function in my "resetScrollPosition" function, using this formula:
this.scheduler1.control.setScrollX(this.scheduler1.control.cellWidth * ((startHour * 60) / this.scheduler1.control.cellDuration));
It works as expected on init, and works on the first time I switch cellDuration, but all following changes also breaks.
I have attached a screenshot of some debuglogs of these functions.
It shows 3 roundtrips into the function "resetScrollPosition" using the setScrollX formula mentioned above.
First one is the init, which returns the expected result. Second time, I switch from cellDuration 5, to 10, that also works as expected. Third I switch back from 10 to 5. Thats when the scrollX I input differs from the actual one set in the Scheduler.