Prevent Read on DataSource Inialization

5 posts, 1 answers
  1. Grant
    Grant avatar
    42 posts
    Member since:
    Jul 2016

    Posted 26 Sep Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    276 posts

    Posted 27 Sep Link to this post

    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.
     
  3. Kendo UI is VS 2017 Ready
  4. Grant
    Grant avatar
    42 posts
    Member since:
    Jul 2016

    Posted 04 Oct in reply to Stefan Link to this post

    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

  5. Grant
    Grant avatar
    42 posts
    Member since:
    Jul 2016

    Posted 04 Oct in reply to Grant Link to this post

    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

  6. Answer
    Stefan
    Admin
    Stefan avatar
    276 posts

    Posted 06 Oct Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready