We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Always original value in editTemplate

I am trying to create a column that uses a checkbox in edit mode. It works, except that args.rowdata always contains the original values when the write function is called. I select a cell, (un)check the checkbox, and leave the cell. The cell now has the new value. But when I select the same cell again, the cell gets reverted to its original value, since args.rowdata["yesNo"] contains the original value.  Is it a bug, or am I supposed to find the correct value for the checkbox somewhere else?

var data = [
    {
        text: "Hello",
        yesNo: true
    },
    {
        text: "World",
        yesNo: false
    }
];

$("#grid").ejGrid({
    dataSource: data,
    
    editSettings: {
        allowEditing: true,
        editMode: "batch"
    },
    
    columns: [
        {
            field: "text",
            headerText: "Text",
            width: 80
        },
        {
            field: "yesNo",
            headerText: "Yes/No",
            editTemplate: {
                create: function () {
                    return "<input type='checkbox' class='trimmaGridCheckBox' />";
                },
                read: function (args) {
                    // Read checkbox state.
                    return args.prop("checked");
                },
                write: function (args) {
                    // Set checkbox state from row data.
                    args.element.prop("checked", args.rowdata["yesNo"]);
                }
            }
        }
    ]
});

3 Replies

BM Balaji Marimuthu Syncfusion Team June 9, 2015 01:34 PM UTC

Hi Linus,

Thanks for using Syncfusion Products.

We considered the requirement “EditTemplate write function is always Maintained the original value ” as a bug. We have logged a report on this and will fix the issue internally, also the fix will be included in Vol 2 Service Pack release which has been scheduled to be rolled out in the month of July 2015.

We have also created an incident internally to have a follow up with this issue.
We suggest you to use the below workaround solution to resolve your reported issue. Please refer the sample and code snippet below:
Sample: Grid

$("#grid").ejGrid({

            dataSource: data,


            editSettings: {

                allowEditing: true,

                editMode: "batch"

            },

            toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] },


            columns: [

                {

                    field: "text",

                    isPrimaryKey: true,

                    headerText: "Text",

                    width: 80

                },

                {

                    field: "yesNo",

                    headerText: "Yes/No",

                    editTemplate: {

                        create: function () {

                            return "<input type='checkbox' class='trimmaGridCheckBox' />";

                        },

                        read: function (args) {

                            // Read checkbox state.

                            return args.prop("checked");

                        },

                        write: function (args) {

                            // Set checkbox state from row data.

                            obj = $("#grid").ejGrid('instance');

                            val = obj._bulkEditCellDetails.cellValue;

                            args.element.prop("checked", val !== undefined ? val : args.rowdata["yesNo"]);

                        }

                    }

                }

            ]
        });


In the above code, we have assigned the edited cell value to the element in edit template write function.

And in the provided code, you have not enabled the isPrimaryKey property. Please set the isPrimaryKey property as true to edit the records. Please refer the documentation for further details.
http://www.syncfusion.com/kb/2675/cant-edit-any-row-except-the-first-row-in-grid


Please let us know if you have any queries.

Regards,
Balaji Marimuthu


LN Linus Nilsson June 9, 2015 01:53 PM UTC

Thank you! The workaround works.


BM Balaji Marimuthu Syncfusion Team June 10, 2015 12:59 PM UTC

Hi Linus,

Happy that the provided workaround works. Please get back to us for further assistance.

Regards,
Balaji Marimuthu

Loader.
Up arrow icon