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

Checkbox Reverting to Original Value on grid.saveChange()

1 Answer 595 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jordan
Top achievements
Rank 1
Jordan asked on 27 Aug 2020, 04:11 PM

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')
 
 
}

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 31 Aug 2020, 10:46 AM

Hello Jordan,

Thank you for the provided code snippets.

Based on them, I tried to reproduce the issue you are experiencing in this Dojo example. You can see that after pressing the SaveChanges button, the new value of the checkbox is saved instead of the original one. Could you please modify the example to replicate the problem? I will then test it and happily assist you.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Jordan
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or