Hello.
I have a grid that contains user information and a few checkbox templates. Whenever I edit set the checkbox to true or vice versa and click save changes the checkbox reverts to its original value.
Here are the main snippets that handle this event:
$("#btnSaveChanges").click(function () {
grid = $("#grid").data("kendoGrid");
grid.saveChanges();
});
function SetActive(e) {
grid = $("#grid").data("kendoGrid");
dataItem = grid.dataItem($(e).closest("tr"));
dataItem.set("IsAssigned", e.checked);
grid.refresh();
}
function renderGrid(value) {
grid = $("#grid").kendoGrid({
dataSource: {
sort: { field: "NameFirst", dir: "asc" },
batch: true,
pageSize: 100,
error: function (e) {
if (typeof e.errors !== 'undefined') {
alert(e.errors);
}
},
requestEnd: function (e) {
if (e.type === "update") {
$('#grid').data('kendoGrid').dataSource.read();
}
},
transport: {
read: {
url: "GetContacts",
dataType: "json",
cache: false,
data: function () {
return {
ID: $("#DDLConceptID").val(),
isNational: $("#DDLConceptID").find('option:selected').attr("data-isNational")
};
}
},
update: {
url: "UpdateContacts",
dataType: "json",
type: "POST"
},
parameterMap: function (data, type) {
if (type === "update") {
return { entities: kendo.stringify(data.models) };
}
else {
return data;
}
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "ContactID",
fields: {
Email: { type: "string" },
IsAssigned: { type: "boolean" },
RoleID: { type: "string" },
ConceptID: { editable: false },
ContactID: { editable: false },
RcvEmail: { type: "boolean" },
RcvQAEmail: { type: "boolean" },
RcvOrderEmail: { type: "boolean" },
Seq: { editable: true },
DistName: { editable: false },
RoleDescription: { type: "string" },
NameFirst: { type: "string" },
NameLast: { type: "string" },
Phone: { type: "string" }
}
}
}
},
sortable: true,
filterable: {
extra: false,
operators: {
string: {
contains: "Contains"
}
}
},
height: 600,
pageable: true,
scrollable: true,
editable: true,
autoBind: value,
columns: [
{ field: "ContactConceptID", title: "Contact ID", hidden: true },
{ field: "ConceptID", title: "Concept ID", hidden: true },
{ field: "ContactID", title: "Contact ID", hidden: true },
{ field: "IsNational", title: "Is National", hidden: true },
{ field: "Seq", title: "Seq", width: 100 },
{ field: "NameFirst", title: "First Name", width: 150 },
{ field: "NameLast", title: "Last Name", width: 150 },
{ field: "Phone", title: "Phone", width: 250 },
{ field: "RoleDescription", title: "Role", width: 140 },
{ field: "RoleID", title: "Type", width: 100, editor: roleIDEditor },
{ field: "Email", title: "E-mail", width: 250 },
{ title: "Assigned", template: '<
input
class
=
"btnActive"
onchange=\'SetActive(this);\'
type
=
"checkbox"
#= IsAssigned ?
checked
=
"checked"
: "" #
class
=
"assignChkbx"
/>', width: 125 },
{ title: "Notes E-mail", template: '<
input
type
=
"checkbox"
#= RcvEmail ?
checked
=
"checked"
: "" #
class
=
"rcvEmailChkbx"
/>', width: 125 },
{ title: "QA E-mail", template: '<
input
type
=
"checkbox"
#= RcvQAEmail ?
checked
=
"checked"
: "" #
class
=
"rcvQAEmailChkbx"
/>', width: 125 },
{ title: "Order E-mail", template: '<
input
type
=
"checkbox"
#= RcvOrderEmail ?
checked
=
"checked"
: "" #
class
=
"rcvOrderEmailChkbx"
/>', width: 125 },
{ field: "DistName", title: "Distributor", width: 200 },
{ command: { name: "Remove", text: "Remove", click: removeBDCAM }, width: 85 }
],//end of columns
}).data('kendoGrid')
}