Change kendo grid Datasource use JS

Std_Net picture Std_Net · May 27, 2013 · Viewed 43.9k times · Source

I have Kendo grid and I set data source use this

.DataSource(dataSource => dataSource
                                .Ajax()
                                .PageSize(20)

                                .Read(read => read.Action("GetWorker", "Worker"))

I have button on my page and I want change datasource when I press this button(use java script). I want do somwthing like this

.DataSource(dataSource => dataSource
                                .Ajax()
                                .PageSize(20)

                                .Read(read => read.Action("GetDisabled", "Worker"))

I try do like this

var grid = $("grid").data("kenodGrid");
            grid.dataSource().read()

but I don't know what to do after grid.dataSource(). how can I change data source? Thnaks and hope for you help

Answer

Lopo picture Lopo · May 28, 2013

I think you should first create a new DataSource (see http://demos.kendoui.com/web/datasource/remote-data.html 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 (http://docs.kendoui.com/api/web/grid#methods-setDataSource)

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