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

dataSource.read() running at random times

9 Answers 313 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 05 Dec 2013, 02:46 PM
Hello and thanks in advance.

I am attempting to retrieve one years worth of events at a time using the navigate event, and checking the year from the args date against the last retrieved date that is being set on a global variable. This logic is working great, however, once I navigate back to 2011 and beyond, or forward to 2014, the read() runs on every navigation without being explicitly called.

Here is my navigate function...

navigate: function(e) {
var year = new Date(e.date).getFullYear();
if (year != app.lastRetrievedYear) {
app.lastRetrievedYear = year;
app.dataSourceUrl = "/api/event/" + year;
dataSource.read();
}
}

And my transport function on my dataSource...

transport: {
read: {
url: function() {
return app.dataSourceUrl;
},
dataType: "json"
}

Per my understanding, the read() shoud only occur on initial load unless otherwise called. I have set breakpoints in FireBug and analyzed my conditional on the navigate and when in 2011, it does not hit this logic, yet still runs the read() function.

Any help? Thanks!

9 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 09 Dec 2013, 03:32 PM
Hi Chris,

Basically this behavior would require custom solution - for example you can use the same "navigate" event handler to get the current year and call the "read" method of the scheduler dataSource. Then you can set custom parameterMap function in which to return current year for the "read" request:

navigate: function (e) {
    var year = new Date(e.date).getFullYear();
 
    if (year != app.lastRetrievedYear) {
        app.lastRetrievedYear = year;
        this.dataSource.read();
    }
},

parameterMap: function (options, operation) {
    if (operation === "read") {
        var scheduler = $("#scheduler").data("kendoScheduler");
                     
        var result = {
            year: app.lastRetrievedYear
        };
                     
        return kendo.stringify(result);
    }
                     
    return kendo.stringify(options);
}

Using the above solution the scheduler dataSource works as expected on our side (even when you navigate to year before 2011). If the scheduler still doesn't request data correctly before 2011 year  - please send us runable example in order to investigate further the exact reasons for this behavior. 

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 09 Dec 2013, 03:43 PM
Vladimir,

With this method, how are you setting the dataSourceUrl? Adding the code you have provided, my request now looks like this: /api/event/2013?{%22year%22:2009}. I should note that I am using a separate dataSource.







0
Vladimir Iliev
Telerik team
answered on 10 Dec 2013, 12:49 PM
Hi Chris,

Could you please provide runable example where the issue is reproduced? This would help us get better overview of your current setup as well as it will allow us to investigate further the exact reason for the "read" request are not being called after 2011 year.

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 10 Dec 2013, 07:39 PM
Vladimir,

I am using this with a WebApi call to Get the data, therefore I need the dataSourceUrl to be /api/event/{year}, and using the parameter map I am getting /api/event/?{year}, how can I not use the parameter format and remove the question mark? Thank you.
0
Vladimir Iliev
Telerik team
answered on 12 Dec 2013, 11:46 AM
Hi Chris,

Could you please provide runable example of your scenario? This would help us better understand what is the exact setup that you have and advice how to proceed further.

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 13 Dec 2013, 09:54 PM
http://jsbin.com/UjANAXu/1/
0
Vladimir Iliev
Telerik team
answered on 17 Dec 2013, 02:48 PM
Hi Chris,

Thank you for the provided code. 

I tested the provided example on our side and it's working as expected as seen in this screencast when tied with WebAPI service. For convenience I attached the example from the screencast to the current thread - could you please check it and let us know how it differs from your real setup? 

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 17 Dec 2013, 05:16 PM
Vladimir, 

I ran the provided solution and am still having the same issue. Once you hit 2009 it pulls it for every month.
0
Accepted
Vladimir Iliev
Telerik team
answered on 19 Dec 2013, 08:12 AM
Hi Chris,

Apologise that I misled you - current behavior is expected as currently the server is returning 0 records for year 2009 and beyond - the dataSource call automatically the "read" action when you navigate and there is 0 records in current data. This behavior can be prevented using global variable (flag) in which to store if current request is explicit call. Then using the "requestStart" event you can prevent current request: 
  • Define global flag: 
    //define variable which to be available in scheduler events
    var isDiffYear = true;
     
    $("#scheduler").kendoScheduler({
  • Modify the "navigate" event handler to set this variable to true before calling the "dataSource" "read" method:  
    navigate: function (e) {
        var year = new Date(e.date).getFullYear();
        if (year != app.lastRetrievedYear) {
            app.lastRetrievedYear = year;
            app.dataSourceUrl = "/api/event/" + year;
            isDiffYear = true;
            dataSource.read();
        }
    }
  • Add "requestStart" event hanler to the dataSource:   
    var dataSource = new kendo.data.SchedulerDataSource({
        requestStart: function (e) {
            if (!isDiffYear) {
                e.preventDefault();
            }
            isDiffYear = false;
        },

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Scheduler
Asked by
Chris
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or