This is a migrated thread and some comments may be shown as answers.

Kendo Grid Update : Getting value of operation as create on Edit/Delete

2 Answers 17 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pallavi
Top achievements
Rank 1
Pallavi asked on 13 Dec 2016, 07:58 AM

I have read all the Threads having this type of discussion based on that I gave Model Id as well. Aslo tried function for Edit and Delete URLs. but no luck.

This code was working earlier after that I added two more grid (which is commented right now) after that all Edit/Delete started coming as operation = create.

 

Here is the code.

 

<script>
$m = jQuery.noConflict();
</script>

 

$m("#siteInspectiongrid").kendoGrid({
dataSource: {
error: function (e) {
var msg = e.xhr.responseText;
var String = msg.substring(msg.lastIndexOf(":") + 1, msg.lastIndexOf(";"));
document.getElementById('errorMessage').innerText = String + "!!";
},
transport: {
read: {
url: crudServiceBaseUrl + "/SiteInspectionInfo?userGroup=" + userGroupConfiguration,
dataType: "json"
},
update: {
url: crudServiceBaseUrl + "/SiteInspectionInfo/Update?userGroup=" + userGroupConfiguration,
dataType: "json",
type: "PUT",
contentType: "application/json",
charset: "utf-8"
},
create: {
url: crudServiceBaseUrl + "/SiteInspectionInfo/Create?userGroup=" + userGroupConfiguration,
dataType: "json",
type: "POST",
contentType: "application/json",
charset: "utf-8"
},
destroy: {
url: crudServiceBaseUrl + "/SiteInspectionInfo/Delete?userGroup=" + userGroupConfiguration,
dataType: "json",
type: "DELETE",
contentType: "application/json",
charset: "utf-8"
},
parameterMap: function (options, operation) {
debugger;
if (operation !== "read" && operation !== "create" && options.models) {
return JSON.stringify({
'ReaderGroupID': options.models[0].ReaderGroupID,
'InspectionPercentage': options.models[0].InspectionPercentage,
'modifiedDate': options.models[0].modifiedDate,
'modifiedBy': options.models[0].modifiedBy,
'Active': options.models[0].Active,
'StaffType': options.models[0].StaffType,
'StaffTypeID': options.models[0].StaffTypeID
});
}
if (operation == "create" && options.models) {
return JSON.stringify({
'ReaderGroupID': options.models[0].readerGroupId.ReaderGroupID,
'InspectionPercentage': options.models[0].InspectionPercentage,
'createDate': options.models[0].createDate,
'createdBy': aliasName,
'modifiedDate': options.models[0].modifiedDate,
'modifiedBy': aliasName,
'StaffType': options.models[0].StaffId.StaffId,
'Active': options.models[0].Active
});
}
}
},
batch: true,
pageSize: 5,
schema: {
model: {
id: "Id",
fields: {
SiteCode: { editable: false, nullable: false },
SiteName: { editable: true, nullable: false },
ReaderGroup: { editable: true, nullable: false },
DoorRelay:{editable: true , nullable:false},
StaffType: { editable: true, nullable: false },
InspectionPercentage: { editable: true, nullable: true },
createdBy: { editable: false, nullable: true },
createDate: { editable: false, nullable: true },
modifiedBy: { editable: false, nullable: true },
modifiedDate: { editable: false, nullable: true },
Active: { editable: true, type: "boolean", defaultValue: true }
}
}
}
},
sortable: {
mode: "single",
allowUnsort: false
},
selectable: "multiple row",
pageable: {
buttonCount: 5
},
scrollable: false,
navigatable: true,
toolbar: [{ name: "create"
}],
edit: function (e) {
//======================================================
// Code to look for `hideMe` attribute on a column.
//======================================================
e.sender.columns.forEach(function (element, index /*, array */) {
if (element.hideMe) {
e.container.find(".k-edit-label:eq(" + index + "), "
+ ".k-edit-field:eq( " + index + ")"
).hide();
}
});
//======================================================
// End column hiding code
//======================================================
},
columns: [
{
field: "SiteCode",
title: "SiteCode",
hidden: true
},
{
field: "SiteName",
title: "SiteName"//,
// editor: siteDropDownEditor
},
{
field: "ReaderGroup",
title: "ReaderGroup"//,
//editor: readerGroupDropDownEditor//,
// template: '<a href="\\#" onclick="ReaderGroupDetails(#=ReaderGroupID# )">#=ReaderGroup#</a>'
},
{
field: "ReaderGroupID",
title: "ReaderGroupID",
hidden: true
},
{
field: "DoorRelay",
title: "DoorRelay",
hidden: true
},
{
field: "SearchRelay",
title: "SearchRelay",
hidden: true
},
{
field: "StaffType",
title: "StaffType"//,
// editor: staffDropDownEditor
}
,
{
field: "StaffTypeID",
title: "StaffTypeID",
hidden: true
}
,
{
field: "InspectionPercentage",
title: "Random %"
},
{
field: "createdBy",
title: "CreatedBy",
hideMe: true
}
,
{
field: "createDate",
title: "CreateDate",
hideMe: true
}
,
{
field: "modifiedBy",
title: "ModifiedBy",
hideMe: true
},
{
field: "modifiedDate",
title: "ModifiedDate",
hideMe: true
}
,
{ field: "Active", title: "Activated",
template: "<input type=\"checkbox\" #= Active ? checked='checked' : '' # class=\"check_row\"/>"
}
,
{ command: ["edit", "destroy"], title: "", width: 250 }
],
editable: {
mode: "inline"//,
// template: kendo.template($("#popup_editor").html())
}
});

2 Answers, 1 is accepted

Sort by
0
Pallavi
Top achievements
Rank 1
answered on 13 Dec 2016, 04:24 PM

In Model ID should be one of the field.

in below example if I change Id by SiteCode it works fine,

model: {
id: "Id",
fields: {
SiteCode: { editable: false, nullable: false },
SiteName: { editable: true, nullable: false },
ReaderGroup: { editable: true, nullable: false },
DoorRelay:{editable: true , nullable:false},
StaffType: { editable: true, nullable: false },
InspectionPercentage: { editable: true, nullable: true },
createdBy: { editable: false, nullable: true },
createDate: { editable: false, nullable: true },
modifiedBy: { editable: false, nullable: true },
modifiedDate: { editable: false, nullable: true },
Active: { editable: true, type: "boolean", defaultValue: true }
}

0
Vladimir Iliev
Telerik team
answered on 15 Dec 2016, 07:33 AM
Hello Pallavi,

Basically when the "create" operation is called unexpectedly, this means that there is an issue with the model ID. I created small runable example from the provided code, and when make the "read" operation receive record with valid "Id" field, the "update" and "destroy" operations started working as expected. Could you please make sure that the "read" operation in your real scenario is returning records with valid and unique IDs?

Also here is the example that I use for testing:


Regards,
Vladimir Iliev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Pallavi
Top achievements
Rank 1
Answers by
Pallavi
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Share this question
or