This is a migrated thread and some comments may be shown as answers.

Change Date/View without reloading DataSource

5 Answers 671 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Grant asked on 07 Aug 2017, 01:20 PM

Hi,

As my title suggests I'd like to be able to pragmatically update the date and the view in a Schedule without the DataSoruce automatically reloading after each one is set.

I use a remote datasource and its a waste of resources for me to set the date and the scheduler reads the datasource, then I set the view and the scheduler reads the datasource again.I tried using the one() to preventDefault on navigate before settign either the view or date, but that had no affect. Example here, http://dojo.telerik.com/aHutu

Any advise would be appreciated.

Thanks and kind regards, 
Grant

5 Answers, 1 is accepted

Sort by
0
Tyler
Top achievements
Rank 1
answered on 07 Aug 2017, 07:09 PM

The .one() method is only going to execute once (the first time), so it would only cover the first time you change something and you are changing it twice...

However, the navigate event does not get called when you change the view and date with .view() and .date() methods. You should bind it to the dataBinding event, and put one before changing the view and changing the date, so you have two .one().

Like:

sch.one("dataBinding", function(e) {
    console.log('one off dataBinding');
    e.preventDefault();
  });
  sch.view("day");
  sch.one("dataBinding", function(e) {
    console.log('one off dataBinding');
    e.preventDefault();
  });
  sch.date(new Date());

 

e.preventDefault() will not stop code you have inside that from executing... but it will that event from executing its default behavior (like triggering other events to read data).

0
Grant
Top achievements
Rank 3
Iron
Iron
Iron
answered on 15 Aug 2017, 09:21 AM

Hi Tyler, 

Thanks for getting back to me. Unfortunately I've only been able to get to this reply now.

I've tried implementing your solution but there is no effect. I've created a simple demo (https://dojo.telerik.com/OhEDa) to show this. 
When you run it the first time, 'BINDING' in only logged once as per a default setup. If you then uncomment the last line where the view is reset. Even though the dataBinding is suppose to be prevented the second time, 'BINDING' is logged twice in the console, first time for initialization, the second time when the view is reset. Only after the binding does the 'dataBinding prevention method' execute.
So is the preventDefault working too late?

I've included the event object on the sch.one() callback, and printed it in the console. there is preventDefault function, but its not logged in the scheduler API for the dataBinding event. does this mean is not supported?

Any advise would be appreciated.

Thanks,
Grant

0
Tyler
Top achievements
Rank 1
answered on 15 Aug 2017, 04:23 PM

The reason nothing happens when you have that view change commented out is that the .one() is similar to .on(), but only executed the first time. So dataBinding happens on initial scheduler creation, then you bind a function to happen once the next time dataBinding is executed. 

However, dataBinding and dataBound for the scheduler fires off for just about any kind of change that is going on in the scheduler. I am not 100% sure its exact inner workings, but yes, I noticed that it gets called when you call sch.view() and sch.date() even after setting the .one(), then the function in the .one() is called. 

Perhaps an option to look into is simply use a global flag.

var dataBindThings = false;

$(document).ready(function(){

   scheduler = $('#scheduler').kendoScheduler({

        dataBinding: function(e){

            if(dataBindThings == false){

                    e.preventDefault();

            }

            else{

                   //do your stuff

            }

        }

    }).data('kendoScheduler');

    scheduler.view('day');

    scheduler.date(new Date());

    

});

 

Then set the variable to true only in situations when you want dataBinding to occur. Or if you want it to occur the first time, set it to true initially, and then set it to false in dataBinding.

0
Veselin Tsvetanov
Telerik team
answered on 16 Aug 2017, 01:04 PM
Hi Grant,

I am not sure if I fully understand the issue faced. On the following Dojo you will find a Scheduler and two buttons. By clicking on them, the user could change the current view (to week) or the date (to today). As you will see in the Network tab of the browser developer tools, there is no remote call made on each navigation (to a different view or date).

Do you observe a different behaviour at your end? Is there something that I miss in the described scenario?

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Grant
Top achievements
Rank 3
Iron
Iron
Iron
answered on 17 Aug 2017, 01:39 PM

Hi Gents, 

I just wanted to get my ducks in a row before answering.

@Tyler, Thanks for the idea about using a flag, I did try it, and it lead me to discover I was actually asking the wrong question. It turns out I was trying to prevent the dataBinding thinking that it would prevent a server request. I have no discovered that (obviously) those are two different things.

@Veselin, I was experiencing something different. Whenever I set the date or the view a data request would be made to the server. What made it even stranger was that sometimes manually setting the view would prevent future data retrieval. I have been unable to discover why this was happening.

After all this I have found a solution to my problem, and that was to enable serverFiltering, which would force a data request to be made each time the viewable date range changes. And I replaced the transport.read options with a function, which I can use to prevent a read request from executing if needed.

My apologies for wasting any time and appreciate the effort non-the-less.

Regards,
Grant

Tags
Scheduler
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Tyler
Top achievements
Rank 1
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Veselin Tsvetanov
Telerik team
Share this question
or