Changing in runtime the transport of a custom dataSource

2 posts, 0 answers
  1. Peter
    Peter avatar
    3 posts
    Member since:
    Jun 2017

    Posted 06 Jul Link to this post

    Hi there,

     

    I'm creating a custom datasource

    01.@(Html.Kendo().Grid<Foo>()
    02.    .Name("grid")
    03.    .AutoBind(false)
    04.    .DataSource(dataSource => dataSource
    05.       .Custom()
    06.       .Batch(true)
    07.       .Schema(s =>
    08.         s.Model(model =>
    09.         {
    10.            model.Id(p => p.ID);
    11.            model.Field(x => x.ID).DefaultValue(0);
    12.         })
    13.       )
    14.       .Transport(new
    15.       {
    16.          read = new Kendo.Mvc.ClientHandlerDescriptor() { HandlerName = "customRead" },
    17.          create = new Kendo.Mvc.ClientHandlerDescriptor() { HandlerName = "customCreate" },
    18.          update = new Kendo.Mvc.ClientHandlerDescriptor() { HandlerName = "customUpdate" },
    19.          destroy = new Kendo.Mvc.ClientHandlerDescriptor() { HandlerName = "customDestroy" },
    20.       })
    21.    )
    22.)

     

    I need in runtime to change all the transport's handlers (in JavaScript).

    I've read the documentation and some posts in the forum but I can't make it work. The last thing I tried was this

     

    01.function anotherDestroy(e) {
    02.    console.log("calling anotherDestroy()");
    03.}
    04. 
    05.let ds =
    06.    $("#grid")
    07.        .data("kendoGrid")
    08.        .dataSource;
    09. 
    10.ds.transport.options.destroy = anotherDestroy;

     

    Can someone please tell me what I'm doing wrong?

    Thank you.

  2. Stefan
    Admin
    Stefan avatar
    1277 posts

    Posted 10 Jul Link to this post

    Hello Peter,

    In this scenario, I can suggest using the setOptions method of the Grid to programmatically changed the transport option of its dataSource.

    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-setOptions

    I made an example demonstrating how to change the dataSource transport.read.URL dynamically. It will require the jQuery syntax when the new options are passed, still the same approach can be used in the provided MVC Grid:

    http://dojo.telerik.com/oduqo

    Regards,
    Stefan
    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.
Back to Top