This question is locked. New answers and comments are not allowed.
I am trying to update and create records in the grid but I get the error "Unable to get property 'data' of undefined or null reference" whenever I click "Update".
My grid is defined in the HTML as;
The script to define the grid options is;
And the procedures called to read, update and create data are (the stored procedure will insert the record if ID=0);
When I click "Update" from the grid I get the error reported above, the actual code breaks in kendo.all.min.js at "o=ut(r.data)?r.data(e.data):r.data". Examining the variables shows the "e.data" contains the updated data from the grid but "r" is undefined.
I have tried modifying code based on several examples from the Telerik product demos and documentation as well some responses in the forums but without any success. I'm not clear on the purpose of the "parameterMap" option and have just tried various different code examples in an attempt to get this to work.
Any help on this would be appreciated.
My grid is defined in the HTML as;
<div class="row"> <ul class="nav nav-tabs" style="margin-bottom: 10px;"> <li class="active"><a data-toggle="tab" href="#Users">Users</a></li> <li><a data-toggle="tab" href="#Reports">Reports</a></li> <li><a data-toggle="tab" href="#Sections">Sections</a></li> <li><a data-toggle="tab" href="#Charts">Charts</a></li> </ul> <div class="tab-content"> <div id="Users" class="tab-pane fade in active"> <kendo-grid options="userGridOptions"></kendo-grid> </div> <div id="Reports" class="tab-pane fade"> <h3>Report Maintenance</h3> </div> <div id="Sections" class="tab-pane fade"> <h3>Section Maintenance</h3> </div> <div id="Charts" class="tab-pane fade"> <h3>Chart Maintenance</h3> </div> </div></div>The script to define the grid options is;
$scope.userGridOptions = { dataSource: { transport: { read: "/Home/GetUsers", dataType: "json", type: "POST" }, update: { url: "/Home/UpdateUser", dataType: "json", type: "POST" }, create: { url: "/Home/UpdateUser", dataType: "json", type: "POST" }, parameterMap: function (data, operation) { if (operation !== "read") { return kendo.stringify(data); } }, batch: false, pageSize: 15, schema: { model: { id: "id", fields: { id: { type: "number", editable: false, nullable: true, defaultValue: 0 }, loginName: { type: "string", validation: { required: true } }, firstName: { type: "string", validation: { required: true } }, lastName: { type: "string", validation: { required: true } }, position: { type: "string", validation: { required: true } }, email: { type: "string", validation: { required: true } }, active: { type: "boolean", validation: { required: true }, defaultValue: true}, updatedBy: { type: "string", editable: false, nullable: true }, updatedDtTm: { type: "date", editable: false, nullable: true }, rowVersion: { type: "string", editable: false, nullable: true }, } } } }, height: "500px", selectable: "row", filterable: true, sortable: true, pageable: true, toolbar: ["create"], editable: { mode: "inline", update: true, destroy: false }, columns: [ { field: "id", title: "User ID" }, //, width: "60px" { field: "active", title: "Active", template: '<input type="checkbox" #= active ? "checked=checked" : ""#></input>' }, //width: "80px", { field: "loginName", title: "Login Name" }, //, width: "250px" { field: "firstName", title: "First Name" }, //, width: "200px" { field: "lastName", title: "Last Name" }, //, width: "200px" { field: "position", title: "Position" }, //, width: "200px" { field: "email" }, { command: ["edit"], title: " "} ]};And the procedures called to read, update and create data are (the stored procedure will insert the record if ID=0);
public ActionResult GetUsers(){ List<User> lstUsers = new List<User>(); var users = from rt in ctx.tblUsers orderby rt.NameLast, rt.NameFirst select rt; try { foreach (var item in users) { User userItem = new User(); userItem.ID = item.ID; userItem.LoginName = item.NameLogin; userItem.FirstName = item.NameFirst; userItem.LastName = item.NameLast; userItem.Position = item.Title; userItem.Email = item.Email; userItem.Active = item.Active; userItem.UpdatedBy = item.UpdatedBy; userItem.UpdatedDtTm = item.UpdatedDtTm; userItem.RowVersion = item.RowVersion; lstUsers.Add(userItem); } return GetJsonResult(lstUsers); } catch (Exception ex) { List<string> errors = new List<string>(); errors.Add(ex.Message); if (ex.InnerException != null) errors.Add(ex.InnerException.Message); return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, string.Join("<br />", errors)); }}public ActionResult UpdateUser(User UserData){ try { var results = ctx.usp_Users_Update(UserData.ID, UserData.LastName, UserData.FirstName, UserData.LoginName, UserData.Position, UserData.Email, UserData.Active, UserData.UpdatedBy, UserData.UpdatedDtTm, UserData.RowVersion); return GetJsonResult(results); } catch (Exception ex) { List<string> errors = new List<string>(); errors.Add(ex.Message); if (ex.InnerException != null) errors.Add(ex.InnerException.Message); return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, string.Join("<br />", errors)); }}When I click "Update" from the grid I get the error reported above, the actual code breaks in kendo.all.min.js at "o=ut(r.data)?r.data(e.data):r.data". Examining the variables shows the "e.data" contains the updated data from the grid but "r" is undefined.
I have tried modifying code based on several examples from the Telerik product demos and documentation as well some responses in the forums but without any success. I'm not clear on the purpose of the "parameterMap" option and have just tried various different code examples in an attempt to get this to work.
Any help on this would be appreciated.