Hi,
I'm having some trouble to change my Kendo Grid´s DataSource to display some
JSON data retrieved by my controller. My controller function looks like:
public ActionResult GetNewData([DataSourceRequest] DataSourceRequest request)
{
List<MyModel> myList = GetDataFromSomewhere();
return Json(myList, "text/html", Encoding.UTF8, JsonRequestBehavior.AllowGet);
//return Json(myList.ToDataSourceResult(request), "text/html",
//Encoding.UTF8, JsonRequestBehavior.AllowGet);
}
Also tried with return type of [string, JsonResult].
My Grid´s Definition was done using HTMLHelper and looks like:
@(Html.Kendo().Grid<MyModel>()
.Columns(c => c.Bound(m => m.Description).Title("Description"))
.DataSource(ds => ds
.Ajax().ServerOperation(false)
.Model(m => m.Id(s => s.Description)))
.Name("MyGrid")
.Selectable()
.Sortable())
Maybe I'm still thinking the wrong way, but my final goal would be to have two
Grids on-screen.
The Change-Event of the first Grid would trigger some JS-Function including the
Ajax-Block below to re-read some dependent data into the second grid.
$.ajax({
contentType: "json",
url: '@Url.Action("GetNewData", "Home")',
method: 'GET',
success: function (d) {
var g = $("#MyGrid").data("kendoGrid");
//var data = [{"Description":"Desc1"},
// {"Description":"Desc2"},
// {"Description":"Desc3"},
// {"Description":"Desc4"}];
g.dataSource = new kendo.data.DataSource({ data: d });
g.dataSource.read();
g.refresh();
alert("Data:" + d); // Displays excactly the same string as stored in ´data´
}
});
The Json-Data-Array displayed in the last alert looks fine (exactly the same string as stored in ´data´):
[{"Description":"Desc1"},
{"Description":"Desc2"},
{"Description":"Desc3"},
{"Description":"Desc4"}];
When I then launch it for
g.dataSource = new kendo.data.DataSource({ data: d });
the Grid keeps empty but doing it with my local data array of ´data´ it represents the data:
g.dataSource = new kendo.data.DataSource({ data: data });
I'm still struggeling to find a working combination of providing parameters for the DataSource. Any help would be highly appreciated.
Many thanks in advance.
I'm having some trouble to change my Kendo Grid´s DataSource to display some
JSON data retrieved by my controller. My controller function looks like:
public ActionResult GetNewData([DataSourceRequest] DataSourceRequest request)
{
List<MyModel> myList = GetDataFromSomewhere();
return Json(myList, "text/html", Encoding.UTF8, JsonRequestBehavior.AllowGet);
//return Json(myList.ToDataSourceResult(request), "text/html",
//Encoding.UTF8, JsonRequestBehavior.AllowGet);
}
Also tried with return type of [string, JsonResult].
My Grid´s Definition was done using HTMLHelper and looks like:
@(Html.Kendo().Grid<MyModel>()
.Columns(c => c.Bound(m => m.Description).Title("Description"))
.DataSource(ds => ds
.Ajax().ServerOperation(false)
.Model(m => m.Id(s => s.Description)))
.Name("MyGrid")
.Selectable()
.Sortable())
Maybe I'm still thinking the wrong way, but my final goal would be to have two
Grids on-screen.
The Change-Event of the first Grid would trigger some JS-Function including the
Ajax-Block below to re-read some dependent data into the second grid.
$.ajax({
contentType: "json",
url: '@Url.Action("GetNewData", "Home")',
method: 'GET',
success: function (d) {
var g = $("#MyGrid").data("kendoGrid");
//var data = [{"Description":"Desc1"},
// {"Description":"Desc2"},
// {"Description":"Desc3"},
// {"Description":"Desc4"}];
g.dataSource = new kendo.data.DataSource({ data: d });
g.dataSource.read();
g.refresh();
alert("Data:" + d); // Displays excactly the same string as stored in ´data´
}
});
The Json-Data-Array displayed in the last alert looks fine (exactly the same string as stored in ´data´):
[{"Description":"Desc1"},
{"Description":"Desc2"},
{"Description":"Desc3"},
{"Description":"Desc4"}];
When I then launch it for
g.dataSource = new kendo.data.DataSource({ data: d });
the Grid keeps empty but doing it with my local data array of ´data´ it represents the data:
g.dataSource = new kendo.data.DataSource({ data: data });
I'm still struggeling to find a working combination of providing parameters for the DataSource. Any help would be highly appreciated.
Many thanks in advance.