I have an empty div that I want to initialize into a kendo grid using Model data. It should be something like the following, but I cannot load the data
$("#mapsDiv").kendoGrid({ sortable: true, dataSource: { transport: { read:"/Home/About", dataType: "odata" }, pageSize: 5 }, pageable: true, resizable: true, columnMenu: true, scrollable:true, navigatable: true, editable: "incell" });
About.cshtml
@model List<KendoExample.Entities.ShortStudent> <div class="row"> <div class="col-md-12 table-responsive" id="mapsDiv"> </div>
My home controller is as follows
List<ShortStudent> students = new List<ShortStudent>(); ShortStudent student1 = new ShortStudent(); student1.birthdate = new DateTime(1999, 4, 30); student1.classname = "1B"; student1.firstname = "Fredie"; student1.surname = "Fletcher"; student1.studentid = 1; ShortStudent student2 = new ShortStudent(); student2.birthdate = new DateTime(2010, 5, 4); student2.classname = "1B"; student2.firstname = "Lee"; student2.surname = "Hobbs"; student2.studentid = 2; students.Add(student1); students.Add(student2); return View(students);
I saw examples using json but not odata ...
In addition, there are examples to use it as
@(Html.Kendo().Scheduler<MeetingViewModel>() .Name("scheduler") .Editable(false) .DataSource(ds => ds .Custom() .Batch(true) .Schema(schema => schema .Model(m => { m.Id(f => f.MeetingID); m.Field("title", typeof(string)).DefaultValue("No title").From("Title"); m.Field("start", typeof(DateTime)).From("Start"); m.Field("end", typeof(DateTime)).From("End"); m.Field("description", typeof(string)).From("Description"); m.Field("recurrenceID", typeof(int)).From("RecurrenceID"); m.Field("recurrenceRule", typeof(string)).From("RecurrenceRule"); m.Field("recurrenceException", typeof(string)).From("RecurrenceException"); m.Field("isAllDay", typeof(bool)).From("IsAllDay"); m.Field("startTimezone", typeof(string)).From("StartTimezone"); m.Field("endTimezone", typeof(string)).From("EndTimezone"); })) .Transport(new {
which I cannot understand / implement, please ignore this solution.
Currently, I see a grid footer that says (1 - 2 out of 4852 elements) with no title or content (datarows) on my screen. What am I doing wrong?
UPDATE
var dataSource = new kendo.data.DataSource( { transport: { read: { url: '@Url.Action("About", "Home")', contentType: "application/json", dataType: "json" } }, schema: { model: { fields: { firstname: { type: "string" }, surname: { type: "string" }, birthdate: { type: "date" }, classname: { type: "string" } } } }, type: "json", serverPaging: false, serverFiltering: true, serverSorting: false } ); $("#mapsDiv") .kendoGrid( { sortable: true, dataSource: { transport: { read: dataSource }, pageSize: 2 }, pageable: true, resizable: false, columnMenu: true, scrollable:true, navigatable: true, editable: "incell", columns:[{ field: "firstname", },{ field: "surname", },{ field: "classname", },{ field: "age", }] });
Homecontroller
public ActionResult About() { .... return View(students); }
Now there is a grid with a header, but no data. If I change the action to json, it returns plain json on the page
public ActionResult About() { .... return Json(students, JsonRequestBehavior.AllowGet); }