I'm trying to build an interface where I change the grid's datasource based on a drop down. The datasource is dynamic (meaning I don't know what columns will returned).
If I use the kendo.data.DataSource set to a static set of JSON data, it populates during the on_change event properly.
If I use an external source... nothing happens. The data is fetched from the server, but nothing renders. I'm really stuck.
I dumbed it down to raw basics... but still no progress. Can someone spot my mistake or give me advice?
I suspect something to do with the DataSourceRequest parameter.... but I can't spot it.
Thanks!
Sam
@(Html.Kendo().Grid<dynamic>()
.Name("logViewGrid")
.Pageable(pager => pager
.Input(false)
.ButtonCount(4)
.PageSizes(new int[] {5, 10, 20, 100, 500})
.AlwaysVisible(false)
)
.Sortable()
.ToolBar(t => {
t.Excel();
t.Search();
})
.Excel(excel => excel
.AllPages(true)
)
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Menu))
.HtmlAttributes(new { style = "height:430px;" })
)
<script>
var logDataSource2 = new kendo.data.DataSource({data: [
{ name: "John Doe", age: 33 },
{ name: "Joe Smith", age: 55 }
]
});
var logDataSource;
function logViewDropdown_change() {
var value = $("#logViewDropdown").val();
if (value != "")
{
logDataSource = new kendo.data.DataSource({
type: "odata",
serverFiltering: true,
serverPaging: true,
serverSorting: true,
pageSize: 10,
transport: {
read: {
url: "/Log/GetLogDataForOne"
}
}
});
var grid = $("#logViewGrid").data("kendoGrid");
grid.setDataSource(logDataSource); // this works if I set it to logDataSource2
}
</script>
Here's my test controller:
[Authorize(Roles = "Log Admin")]public IActionResult GetLogDataForOne([DataSourceRequest] DataSourceRequest request)
{
System.Collections.Generic.IEnumerable<dynamic> dynamicList;
dynamicList = Global.SqlDataAccess.GetDynamicData("SELECT TOP 2 ActivityInformation FROM log.WebsiteActivity");
return Json(dynamicList.ToDataSourceResult(request)); //
}