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

Prevent Read on DataSource Inialization

4 Answers 2764 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Grant asked on 26 Sep 2016, 10:10 AM

Hi there, 

Im creating a kendoScheduler that retrieves events for a specific user, see below code (shortened for brevity):

Controller:

@RequestMapping(value="/forUserCalendar", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<KendoSchedulerEvent> getCalendarEventsForUser(@RequestParam(value="userId", required = true) Long userId) {
  System.out.println("### forUserCalendar..."+userId);
     
  //Retrieves events from Database
 
  //Converts Domain Events to KendoSchedulerEvents
  return KendoSchedulerEvent.convertEvents(events);
}

HTML:

var dataSource_events = new kendo.data.SchedulerDataSource({
  transport: {
    read: {
      url: "/itd-boot-thymeleaf-demo/events/forUserCalendar",
      dataType: "json",
      type: "GET"
    },
         
    parameterMap: function(options, operation) {
      if (operation === "read") {
        var userId = $("#select-users").getKendoDropDownList().value();
        var result = {
          userId: userId,
        }
        return result;
      }
      return options;  
    }
  }
});
 
$("#scheduler-calendar").kendoScheduler({
  autoBind: false,
  dataSource: dataSource_events
});
 
$("#select-users").kendoDropDownList({
  dataSource: dataSource_users,
  dataValueField: "id",
  dataTextField: "fullName",
     
  change: function() {
    if (this.value() != "") {
      $("#scheduler-calendar").getKendoScheduler().dataSource.read();
    }
  }
});

The Problem:
When my page loads, the read URL is being called from the DS, but there wont be a user selected at this stage as the page just loaded. Is there a way to prevent the DS from being read when its initialized? I thouhg that by including "autoBind" in the Scheduler would help, but its had no effect.

Please advise if you can.

Many Thanks,
Grant

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 27 Sep 2016, 02:50 PM
Hello Grant,

The autoBind property of the Scheduler should prevent the initial calling to the dataSource:

http://docs.telerik.com/kendo-ui/api/javascript/ui/scheduler#configuration-autoBind

Also, I made an example with a remote dataSource and the autoBind property set to false, and it is working as expected:

http://dojo.telerik.com/uXOCu

I can assume that the initial call is caused by a custom function which is causing the change event of the Scheduler to be fired. When the change event of the Scheduler is fired the data is fetched even if the autoBind is set to false.

In order to further investigate the issue, please send a fully runnable example that reproduces it.
 
Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 04 Oct 2016, 09:04 AM

Hi Stefan, 

Please excuse my delayed response, something else came up. Turns out that when I shortened my code for you, I removed the code that was causing the problem.

My Scheduler initialization actually looks like this:

$("#scheduler-calendar").kendoScheduler({
  autoBind: false,
  dataSource: dataSource_events
}).getKendoScheduler().view("month");
My changing the view was triggering a read of the DS immediately, which of course would fail.

My apologies for wasting your time with working code.

That being said, is there a way to set the view of the calendar to 'month' when initializing, as it sets itself to 'day' by default?

Side Bar:
I read this (http://docs.telerik.com/kendo-ui/intro/widget-basics/events-and-methods#jquery-data-method) article on retrieving an instance of a kendo widget. I didnt quite understand the difference. Is one method better than the other? Can you elaborate a bit on the difference or point me to a helpful article.

Many Thanks,
Grant

0
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 04 Oct 2016, 09:08 AM

Nevermind about the setting the view to 'month' onload, I found it in the views.selected attribute.

If you could just help with my side bar, I'd appreciate that.

Thanks,
Grant

0
Accepted
Stefan
Telerik team
answered on 06 Oct 2016, 06:10 AM
Hello Grant,

Small differences can be that when the getKendo is used this will give an IntelliSense for types.

Also, in the documentation, most of the examples are using the jQuery method, but the reason is that the getKendo method is newer and it was not available when these examples were made.

Both methods for getting the widget instance are essentially the same. You can choose the method you prefer more.

Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Data Source
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Stefan
Telerik team
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or