We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get schedule start and end date on page load

Hi, at the time the scheduler initially loads, how can I get the current view start and end date? I tried this.scheduleObj.getCurrentViewDates() but it is empty.

5 Replies

VD Vinitha Devi Murugan Syncfusion Team November 18, 2019 02:17 AM

Hi Jose, 
 
Syncfusion Greetings. 
 
We achieved your requirement by making use of created event of the scheduler. Please refer below sample. 
 
 
  onCreated(): void { 
    // To get current view date we used getCurrentViewDates public method 
    let currentViewDates: Date[] = this.scheduleObj.getCurrentViewDates() as Date[]; 
    let startDate: Date = currentViewDates[0] as Date; 
    let endDate: Date = currentViewDates[currentViewDates.length - 1] as Date; 
    console.log(startDate); 
    console.log(endDate); 
  } 
 
Regards, 
M.Vinitha devi 



JL jose lara November 30, 2019 04:32 PM

Thx. This works inside the onCreated() method. But, when I use the same logic inside of onNavigating() method, the dates are one week behind. How can I get the current dates in other events as well? 


VD Vinitha Devi Murugan Syncfusion Team December 2, 2019 02:32 AM

Hi Jose, 
 
Thanks for your update. 
 
You can get the start and end date of current date range by making use of actionComplete event with args.requestType viewNavigate and dateNavigate. For the same we have prepared the below sample, kindly refer it. 
 

//To get the start and end dates of current view and current Date range 
  onActionComplete(args): void { 
    if ( args.requestType === "viewNavigate" || args.requestType === "dateNavigate") { 
      var currentViewDates = this.scheduleObj.getCurrentViewDates(); 
      var startDate = currentViewDates[0]; 
      var endDate = currentViewDates[currentViewDates.length - 1]; 
      console.log(startDate); 
      console.log(endDate); 
    } 
  } 
 
Note: Naviagating event triggers before the date or view navigation takes place on scheduler. 
 
Regards, 
M.Vinitha devi 



LG Luis Gomez August 18, 2021 05:36 AM

Hi, I'm experiencing this problem in Vue


this.$refs.scheduler.getCurrentViewDates() is empty onCreated()





VD Vinitha Devi Murugan Syncfusion Team August 19, 2021 04:05 AM

Hi Luis, 
 
Thanks for your update. 
 
We have validated your reported query at our end with your shared code. To resolve your reported issue we suggest you to use below code in your sample. 
 
 
onCreatefunction (args) { 
    console.log(this.$refs.scheduler.ej2Instances.getCurrentViewDates()); 
}, 
 
Kindly try with the above solution and get back to us if you need any further assistance 
 
Regards, 
Vinitha 


Loader.
Live Chat Icon For mobile
Up arrow icon