Change Kendo Grid Datasource Use JS


Answer :

I think you should first create a new DataSource (see https://demos.telerik.com/kendo-ui/datasource/remote-data-binding for remote data)

var dataSource = new kendo.data.DataSource({     data: [         { name: "John Doe", age: 33 }     ] }); 

And then append it to the grid by using the setDataSource method (https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/methods/setdatasource)

var grid = $("#grid").data("kendoGrid"); grid.setDataSource(dataSource); 

Since you want to change the action for your read then you can just do that. According to this question you could just set the dataSource Read url and refresh your grid data with something like that:

var grid = $("#grid").data("kendoGrid"); grid.dataSource.transport.options.read.url = "newUrlPath"; grid.dataSource.read(); grid.refresh(); 

If you don't actually want to change your dataSource but your data and possibly get your list of items from some ajax request as json then I will write down the way I do it as an example in case someone wants it.

var jsonData = ... // From some ajax response var newKendoDatasource = newKendoDS(jsonData); $("#grid").data("kendoGrid").dataSource.data(newKendoDatasource._data); 

The function is like the above pretty much

function newKendoDS(ndata) {     var datasource = new kendo.data.DataSource({ data: ndata });     datasource.read(); // In order to refresh     return datasource; } 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?