How to Put the previous Value on Navigation DatePicker.

Hello,

I am using javascript room Scheduler ej2.  when I am clicking the date from date picker (Navigation date picker). if the current view is 'TimelineDay' and if selected date is not in range of a given startDate and endDate put back the previous selected Date to the date picker. and prev date should be active in the date picker.

For Example, i have a WeekStartDate='18-01-2021' and WeekEndDate='24-01-2021'. if prev selected date is '20-01-2021' in TimelineDay view and when i selected the date '27-01-2021'. since it is not between my WeekStartDate and WeekEndDate I want the active date back (which should be prev date ' 20-01-2021'.

Please take a look on below codes and attachment.

navigating: function (args)  { 
                if (args.action == "date") { 
                    if(args.currentView == "TimelineDay"){
                        if(args.currentDate < WeekStartDate || args.currentDate > WeekEndDate){
                            args.cancel=true;
                            args.currentDate=args.previousDate;
                        }
                    }
                } 
      } 


Attachment: put_prev_value_d014b08d.zip

1 Reply 1 reply marked as answer

NR Nevitha Ravi Syncfusion Team January 18, 2021 11:31 AM UTC

Hi Atish, 

Greetings from Syncfusion Support. 

We have prepared a sample for your requirement ‘maintain previous date on specific condition’ by reducing setting args.cancel to true can be viewed from the following link. 

Also we have checked the shared code in which you have checked args.currentView which will be undefined when action type is date. So we have modified that in the above sample to meet your requirement. 

navigating: (args: NavigatingEventArgs) => { 
    if (args.action == "date") { 
      console.log("navigating"); 
      var weekStartDate = new Date(2021, 0, 18); 
      var weekEndDate = new Date(2019, 0, 24); 
      var sObj = document.querySelector(".e-schedule").ej2_instances[0]; 
      if (args.action == "date") { 
        if (sObj.currentView == "TimelineDay") { 
          if ( 
            args.currentDate < weekStartDate || 
            args.currentDate > weekEndDate 
          ) { 
            args.cancel = true; 
          } 
        } 
      } 
    } 
  } 

Please try the above solution and let us know whether if you need any further assistance. 

Regards, 
Nevitha 


Marked as answer
Loader.
Up arrow icon