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

Changing in runtime the transport of a custom dataSource

1 Answer 415 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 06 Jul 2017, 01:23 PM

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.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 10 Jul 2017, 10:03 AM
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, 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 (charts) and form elements.
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or