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

How to change the grid datasource using jQuery and calling an MVC controller

1 Answer 467 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 21 Oct 2013, 08:40 PM
I have been looking through the postings but can't find one that addresses by specific issue.  I have a grid that is being loaded with data just fine on the initial page request.  But now the user wants to select a subset of the data.

Here is the grid HTML helper from the MVC razor view page:

@(Html.Kendo().Grid<AdvisorSearchResultsVM>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(a => a.AdvisorID);
columns.Bound(a => a.CIFID);
columns.Bound(a => a.FirstName);
columns.Bound(a => a.LastName);
columns.Bound(a => a.Status);
})
.Sortable()
.Pageable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("onError"))
.Model(model =>
{
model.Id(a => a.AdvisorID);
                                model.Field(a => a.AdvisorID).Editable(false);  
})
                            .Read(read => read.Action("GetAdvisors","Advisor"))
)
)

I want to change the grid datasource action to call the Advisor controller GetRegistered method.

I tried doing this in a javascript method

$("#Grid").kendoGrid.dataSource.transport.options.read.action("/Advisor/GetRegistered");

But I get an error that says  $(...).kendoGrid.dataSource is undefined.

Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Oct 2013, 02:21 PM
Hello,

The object should be found from the element data. The new URL should also be assigned to the "url" field:

$("#Grid").data("kendoGrid").dataSource.transport.options.read.url = newUrl;
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or