I'm unable to load any data from my server into a grid that I'm trying to setup for simple paging without resorting to using the solution posted in the Kendo Grid Forum that uses a jquery ajax request to directly populate the "data" member directly of the kendo.data.DataSource. I am returning a simple json response that contains an array and a count to support paging (for example):
{"artists":[{"ID":4471,"Name":"10 Years","Gender":"Male","Category":"Pop/Rock"},{"ID":4391,"Name":"10,000 Maniacs","Gender":"Female","Category":"Pop/Rock"},{"ID":15,"Name":"10cc","Gender":"Male","Category":"Pop/Rock"},"count":2004}This is my 1st cut at a datasource, and I've verified the server gets called and returns the json as above, but nothing displays in the grid:
var artistSource = new kendo.data.DataSource({ transport: { read: { url: "http://localhost:53596/api/Artists?format=json", dataType: "jsonp" }, schema: { data: "artists", total: "count", model: { fields: { ID: { type: "number"}, Name: { type: "string"}, Gender: { type: "string"}, Category: { type: "string"} } } }, page: 1, pageSize: 50, serverPaging: true, serverFiltering: true, serverSorting: true }});Following the workaround above, this datasource below works. From what I can tell, I'm following the examples, but I'm not able to get the datasource populated properly, and I'd really appreciate any help!
// This is the ajax call that is used to populate the data// member in the dataSource as described in the workaround in the forums: function GetArtists() { var _resData; $.ajax({ type: 'GET', url: 'http://localhost:53596/api/Artists?format=json', dataType: 'json', success: function (data) { _resData = data.artists; }, data: {}, async: false }); return _resData;}// This datasource populates the data array via a jquery ajax call,// bypassing the configuration as done in the original datasource.var artistSource2 = new kendo.data.DataSource({ data: GetArtists(), schema: { model: { fields: { ID: { type: "number" }, Name: { type: "string" }, Gender: { type: "string" }, Category: { type: "string" } } } } }); // If I use artistSource2 (the workaround), the grid gets populated, // but if I use artistSource, nothing shows up in the grid. $('#Artists').kendoGrid({ dataSource: artistSource2, height: 600, columns: [{ field: "ID" }, { field: "Name" }, { field: "Gender" }, { field: "Category"}], pageable: true });